This repository was archived by the owner on Jul 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Building AST, added AST type spec from graphql-js for reference
- Loading branch information
Josh Price
committed
Sep 13, 2015
1 parent
5c8e89e
commit 37ede48
Showing
5 changed files
with
668 additions
and
135 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,333 @@ | ||
/* @flow */ | ||
/** | ||
* Copyright (c) 2015, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
*/ | ||
|
||
import type { Source } from './source'; | ||
|
||
|
||
/** | ||
* Contains a range of UTF-8 character offsets that identify | ||
* the region of the source from which the AST derived. | ||
*/ | ||
export type Location = { | ||
start: number; | ||
end: number; | ||
source?: ?Source | ||
} | ||
|
||
/** | ||
* The list of all possible AST node types. | ||
*/ | ||
export type Node = Name | ||
| Document | ||
| OperationDefinition | ||
| VariableDefinition | ||
| Variable | ||
| SelectionSet | ||
| Field | ||
| Argument | ||
| FragmentSpread | ||
| InlineFragment | ||
| FragmentDefinition | ||
| IntValue | ||
| FloatValue | ||
| StringValue | ||
| BooleanValue | ||
| EnumValue | ||
| ListValue | ||
| ObjectValue | ||
| ObjectField | ||
| Directive | ||
| ListType | ||
| NonNullType | ||
| ObjectTypeDefinition | ||
| FieldDefinition | ||
| InputValueDefinition | ||
| InterfaceTypeDefinition | ||
| UnionTypeDefinition | ||
| ScalarTypeDefinition | ||
| EnumTypeDefinition | ||
| EnumValueDefinition | ||
| InputObjectTypeDefinition | ||
| TypeExtensionDefinition | ||
|
||
// Name | ||
|
||
export type Name = { | ||
kind: 'Name'; | ||
loc?: ?Location; | ||
value: string; | ||
} | ||
|
||
// Document | ||
|
||
export type Document = { | ||
kind: 'Document'; | ||
loc?: ?Location; | ||
definitions: Array<Definition>; | ||
} | ||
|
||
export type Definition = OperationDefinition | ||
| FragmentDefinition | ||
| TypeDefinition | ||
|
||
export type OperationDefinition = { | ||
kind: 'OperationDefinition'; | ||
loc?: ?Location; | ||
// Note: subscription is an experimental non-spec addition. | ||
operation: 'query' | 'mutation' | 'subscription'; | ||
name?: ?Name; | ||
variableDefinitions?: ?Array<VariableDefinition>; | ||
directives?: ?Array<Directive>; | ||
selectionSet: SelectionSet; | ||
} | ||
|
||
export type VariableDefinition = { | ||
kind: 'VariableDefinition'; | ||
loc?: ?Location; | ||
variable: Variable; | ||
type: Type; | ||
defaultValue?: ?Value; | ||
} | ||
|
||
export type Variable = { | ||
kind: 'Variable'; | ||
loc?: ?Location; | ||
name: Name; | ||
} | ||
|
||
export type SelectionSet = { | ||
kind: 'SelectionSet'; | ||
loc?: ?Location; | ||
selections: Array<Selection>; | ||
} | ||
|
||
export type Selection = Field | ||
| FragmentSpread | ||
| InlineFragment | ||
|
||
export type Field = { | ||
kind: 'Field'; | ||
loc?: ?Location; | ||
alias?: ?Name; | ||
name: Name; | ||
arguments?: ?Array<Argument>; | ||
directives?: ?Array<Directive>; | ||
selectionSet?: ?SelectionSet; | ||
} | ||
|
||
export type Argument = { | ||
kind: 'Argument'; | ||
loc?: ?Location; | ||
name: Name; | ||
value: Value; | ||
} | ||
|
||
|
||
// Fragments | ||
|
||
export type FragmentSpread = { | ||
kind: 'FragmentSpread'; | ||
loc?: ?Location; | ||
name: Name; | ||
directives?: ?Array<Directive>; | ||
} | ||
|
||
export type InlineFragment = { | ||
kind: 'InlineFragment'; | ||
loc?: ?Location; | ||
typeCondition: NamedType; | ||
directives?: ?Array<Directive>; | ||
selectionSet: SelectionSet; | ||
} | ||
|
||
export type FragmentDefinition = { | ||
kind: 'FragmentDefinition'; | ||
loc?: ?Location; | ||
name: Name; | ||
typeCondition: NamedType; | ||
directives?: ?Array<Directive>; | ||
selectionSet: SelectionSet; | ||
} | ||
|
||
|
||
// Values | ||
|
||
export type Value = Variable | ||
| IntValue | ||
| FloatValue | ||
| StringValue | ||
| BooleanValue | ||
| EnumValue | ||
| ListValue | ||
| ObjectValue | ||
|
||
export type IntValue = { | ||
kind: 'IntValue'; | ||
loc?: ?Location; | ||
value: string; | ||
} | ||
|
||
export type FloatValue = { | ||
kind: 'FloatValue'; | ||
loc?: ?Location; | ||
value: string; | ||
} | ||
|
||
export type StringValue = { | ||
kind: 'StringValue'; | ||
loc?: ?Location; | ||
value: string; | ||
} | ||
|
||
export type BooleanValue = { | ||
kind: 'BooleanValue'; | ||
loc?: ?Location; | ||
value: boolean; | ||
} | ||
|
||
export type EnumValue = { | ||
kind: 'EnumValue'; | ||
loc?: ?Location; | ||
value: string; | ||
} | ||
|
||
export type ListValue = { | ||
kind: 'ListValue'; | ||
loc?: ?Location; | ||
values: Array<Value>; | ||
} | ||
|
||
export type ObjectValue = { | ||
kind: 'ObjectValue'; | ||
loc?: ?Location; | ||
fields: Array<ObjectField>; | ||
} | ||
|
||
export type ObjectField = { | ||
kind: 'ObjectField'; | ||
loc?: ?Location; | ||
name: Name; | ||
value: Value; | ||
} | ||
|
||
|
||
// Directives | ||
|
||
export type Directive = { | ||
kind: 'Directive'; | ||
loc?: ?Location; | ||
name: Name; | ||
arguments?: ?Array<Argument>; | ||
} | ||
|
||
|
||
// Type Reference | ||
|
||
export type Type = NamedType | ||
| ListType | ||
| NonNullType | ||
|
||
export type NamedType = { | ||
kind: 'NamedType'; | ||
loc?: ?Location; | ||
name: Name; | ||
}; | ||
|
||
export type ListType = { | ||
kind: 'ListType'; | ||
loc?: ?Location; | ||
type: Type; | ||
} | ||
|
||
export type NonNullType = { | ||
kind: 'NonNullType'; | ||
loc?: ?Location; | ||
type: NamedType | ListType; | ||
} | ||
|
||
// Type Definition | ||
|
||
export type TypeDefinition = ObjectTypeDefinition | ||
| InterfaceTypeDefinition | ||
| UnionTypeDefinition | ||
| ScalarTypeDefinition | ||
| EnumTypeDefinition | ||
| InputObjectTypeDefinition | ||
| TypeExtensionDefinition | ||
|
||
export type ObjectTypeDefinition = { | ||
kind: 'ObjectTypeDefinition'; | ||
loc?: ?Location; | ||
name: Name; | ||
interfaces?: ?Array<NamedType>; | ||
fields: Array<FieldDefinition>; | ||
} | ||
|
||
export type FieldDefinition = { | ||
kind: 'FieldDefinition'; | ||
loc?: ?Location; | ||
name: Name; | ||
arguments: Array<InputValueDefinition>; | ||
type: Type; | ||
} | ||
|
||
export type InputValueDefinition = { | ||
kind: 'InputValueDefinition'; | ||
loc?: ?Location; | ||
name: Name; | ||
type: Type; | ||
defaultValue?: ?Value; | ||
} | ||
|
||
export type InterfaceTypeDefinition = { | ||
kind: 'InterfaceTypeDefinition'; | ||
loc?: ?Location; | ||
name: Name; | ||
fields: Array<FieldDefinition>; | ||
} | ||
|
||
export type UnionTypeDefinition = { | ||
kind: 'UnionTypeDefinition'; | ||
loc?: ?Location; | ||
name: Name; | ||
types: Array<NamedType>; | ||
} | ||
|
||
export type ScalarTypeDefinition = { | ||
kind: 'ScalarTypeDefinition'; | ||
loc?: ?Location; | ||
name: Name; | ||
} | ||
|
||
export type EnumTypeDefinition = { | ||
kind: 'EnumTypeDefinition'; | ||
loc?: ?Location; | ||
name: Name; | ||
values: Array<EnumValueDefinition>; | ||
} | ||
|
||
export type EnumValueDefinition = { | ||
kind: 'EnumValueDefinition'; | ||
loc?: ?Location; | ||
name: Name; | ||
} | ||
|
||
export type InputObjectTypeDefinition = { | ||
kind: 'InputObjectTypeDefinition'; | ||
loc?: ?Location; | ||
name: Name; | ||
fields: Array<InputValueDefinition>; | ||
} | ||
|
||
export type TypeExtensionDefinition = { | ||
kind: 'TypeExtensionDefinition'; | ||
loc?: ?Location; | ||
definition: ObjectTypeDefinition; | ||
} |
Oops, something went wrong.