-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from rigglo/full-language-support
Full language support
- Loading branch information
Showing
7 changed files
with
1,119 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package ast | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
type Document struct { | ||
Operations []*Operation | ||
Fragments []*Fragment | ||
Definitions []Definition | ||
} | ||
|
||
func NewDocument() *Document { | ||
return &Document{ | ||
Operations: []*Operation{}, | ||
Fragments: []*Fragment{}, | ||
Definitions: []Definition{}, | ||
} | ||
} | ||
|
||
const ( | ||
// Executable directive locations | ||
QueryDirectiveLocation string = "QUERY" | ||
MutationDirectiveLocation string = "MUTATION" | ||
SubscriptionDirectiveLocation string = "SUBSCRIPTION" | ||
FieldDirectiveLocation string = "FIELD" | ||
FragmentDefinitionDirectiveLocation string = "FRAGMENT_DEFINITION" | ||
FragmentSpreadDirectiveLocation string = "FRAGMENT_SPREAD" | ||
InlineFragmentDirectiveLocation string = "INLINE_FRAGMENT" | ||
|
||
// TypeSystem directive locations | ||
SchemaDirectiveLocation string = "SCHEMA" | ||
ScalarDirectiveLocation string = "SCALAR" | ||
ObjectDirectiveLocation string = "OBJECT" | ||
FieldDefinitionDirectiveLocation string = "FIELD_DEFINITION" | ||
ArguentDefinitionDirectiveLocation string = "ARGUMENT_DEFINITION" | ||
InterfaceDirectiveLocation string = "INTERFACE" | ||
UnionDirectiveLocation string = "UNION" | ||
EnumDirectiveLocation string = "ENUM" | ||
EnumValueDirectiveLocation string = "ENUM_VALUE" | ||
InputObjectDirectiveLocation string = "INPUT_OBJECT" | ||
InputFieldDefinitionDirectiveLocation string = "INPUT_FIELD_DEFINITION" | ||
) | ||
|
||
func IsValidDirective(d string) bool { | ||
return strings.Contains("QUERY MUTATION SUBSCRIPTION FIELD FRAGMENT_DEFINITION FRAGMENT_SPREAD INLINE_FRAGMENT SCHEMA SCALAR OBJECT FIELD_DEFINITION ARGUMENT_DEFINITION INTERFACE UNION ENUM ENUM_VALUE INPUT_OBJECT INPUT_FIELD_DEFINITION", fmt.Sprintf(" %s ", d)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
package ast | ||
|
||
type DefinitionKind uint | ||
|
||
const ( | ||
SchemaKind DefinitionKind = iota | ||
ScalarKind | ||
ObjectKind | ||
InterfaceKind | ||
UnionKind | ||
EnumKind | ||
InputObjectKind | ||
DirectiveKind | ||
) | ||
|
||
type Definition interface { | ||
Kind() DefinitionKind | ||
} | ||
|
||
type SchemaDefinition struct { | ||
Name string | ||
Directives []*Directive | ||
RootOperations map[OperationType]*NamedType | ||
} | ||
|
||
func (d *SchemaDefinition) Kind() DefinitionKind { | ||
return SchemaKind | ||
} | ||
|
||
type ScalarDefinition struct { | ||
Description string | ||
Name string | ||
Directives []*Directive | ||
} | ||
|
||
func (d *ScalarDefinition) Kind() DefinitionKind { | ||
return ScalarKind | ||
} | ||
|
||
type ObjectDefinition struct { | ||
Description string | ||
Name string | ||
Implements []*NamedType | ||
Directives []*Directive | ||
Fields []*FieldDefinition | ||
} | ||
|
||
func (d *ObjectDefinition) Kind() DefinitionKind { | ||
return ObjectKind | ||
} | ||
|
||
type FieldDefinition struct { | ||
Description string | ||
Name string | ||
Arguments []*InputValueDefinition | ||
Type Type | ||
Directives []*Directive | ||
} | ||
|
||
type InputValueDefinition struct { | ||
Description string | ||
Name string | ||
Type Type | ||
DefaultValue Value | ||
Directives []*Directive | ||
} | ||
|
||
type InterfaceDefinition struct { | ||
Description string | ||
Name string | ||
Directives []*Directive | ||
Fields []*FieldDefinition | ||
} | ||
|
||
func (d *InterfaceDefinition) Kind() DefinitionKind { | ||
return InterfaceKind | ||
} | ||
|
||
type UnionDefinition struct { | ||
Description string | ||
Name string | ||
Directives []*Directive | ||
Members []*NamedType | ||
} | ||
|
||
func (d *UnionDefinition) Kind() DefinitionKind { | ||
return UnionKind | ||
} | ||
|
||
type EnumDefinition struct { | ||
Description string | ||
Name string | ||
Directives []*Directive | ||
Values []*EnumValueDefinition | ||
} | ||
|
||
func (d *EnumDefinition) Kind() DefinitionKind { | ||
return EnumKind | ||
} | ||
|
||
type EnumValueDefinition struct { | ||
Description string | ||
Value *EnumValue | ||
Directives []*Directive | ||
} | ||
|
||
type InputObjectDefinition struct { | ||
Description string | ||
Name string | ||
Directives []*Directive | ||
Fields []*InputValueDefinition | ||
} | ||
|
||
func (d *InputObjectDefinition) Kind() DefinitionKind { | ||
return InputObjectKind | ||
} | ||
|
||
type DirectiveDefinition struct { | ||
Description string | ||
Name string | ||
Locations []string | ||
Arguments []*InputValueDefinition | ||
} | ||
|
||
func (d *DirectiveDefinition) Kind() DefinitionKind { | ||
return DirectiveKind | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.