PHP Class GraphQL\Language\Parser

Show file Open project: webonyx/graphql-php Class Usage Examples

Public Methods

Method Description
__construct ( Source $source, array $options = [] ) Parser constructor.
any ( integer $openKind, callable $parseFn, integer $closeKind ) : array Returns a possibly empty list of parse nodes, determined by the parseFn. This list begins with a lex token of openKind and ends with a lex token of closeKind. Advances the parser to the next lex token after the closing token.
expect ( string $kind ) : Token If the next token is of the given kind, return that token after advancing the parser. Otherwise, do not change the parser state and return false.
expectKeyword ( string $value ) : Token If the next token is a keyword with the given value, return that token after advancing the parser. Otherwise, do not change the parser state and return false.
loc ( Token $startToken ) : Location | null Returns a location object, used to identify the place in the source that created a given parsed object.
many ( $openKind, $parseFn, $closeKind ) : array Returns a non-empty list of parse nodes, determined by the parseFn. This list begins with a lex token of openKind and ends with a lex token of closeKind. Advances the parser to the next lex token after the closing token.
parse ( Source | string $source, array $options = [] ) : DocumentNode Available options:
parseArgument ( ) : ArgumentNode
parseArgumentDefs ( ) : InputValueDefinitionNode[]
parseArguments ( ) : ArgumentNode[]
parseArray ( boolean $isConst ) : ListValueNode
parseConstValue ( ) : BooleanValueNode | EnumValueNode | FloatValueNode | IntValueNode | StringValueNode | VariableNode
parseDefinition ( ) : OperationDefinitionNode | FragmentDefinitionNode | GraphQL\Language\AST\TypeSystemDefinitionNode
parseDirective ( ) : DirectiveNode
parseDirectiveDefinition ( ) : DirectiveDefinitionNode DirectiveDefinition : - directive @ Name ArgumentsDefinition? on DirectiveLocations
parseDirectiveLocations ( ) : NameNode[]
parseDirectives ( ) : DirectiveNode[]
parseDocument ( ) : DocumentNode Implements the parsing rules in the Document section.
parseEnumTypeDefinition ( ) : EnumTypeDefinitionNode
parseEnumValueDefinition ( ) : EnumValueDefinitionNode
parseField ( ) : FieldNode
parseFieldDefinition ( ) : FieldDefinitionNode
parseFragment ( ) : FragmentSpreadNode | InlineFragmentNode
parseFragmentDefinition ( ) : FragmentDefinitionNode
parseFragmentName ( ) : NameNode
parseImplementsInterfaces ( ) : NamedTypeNode[]
parseInputObjectTypeDefinition ( ) : InputObjectTypeDefinitionNode
parseInputValueDef ( ) : InputValueDefinitionNode
parseInterfaceTypeDefinition ( ) : InterfaceTypeDefinitionNode
parseName ( ) : NameNode Converts a name lex token into a name parse node.
parseNamedType ( )
parseObject ( $isConst ) : ObjectValueNode
parseObjectField ( $isConst ) : ObjectFieldNode
parseObjectTypeDefinition ( ) : ObjectTypeDefinitionNode
parseOperationDefinition ( ) : OperationDefinitionNode
parseOperationType ( ) : string
parseOperationTypeDefinition ( ) : OperationTypeDefinitionNode
parseScalarTypeDefinition ( ) : ScalarTypeDefinitionNode
parseSchemaDefinition ( ) : SchemaDefinitionNode
parseSelection ( ) : mixed Selection : - Field - FragmentSpread - InlineFragment
parseSelectionSet ( ) : SelectionSetNode
parseType ( Source | string $source, array $options = [] ) : ListTypeNode | NameNode | NonNullTypeNode Given a string containing a GraphQL Type (ex. [Int!]), parse the AST for that type.
parseTypeExtensionDefinition ( ) : TypeExtensionDefinitionNode
parseTypeReference ( ) : ListTypeNode | NameNode | NonNullTypeNode Handles the Type: TypeName, ListType, and NonNullType parsing rules.
parseTypeSystemDefinition ( ) : GraphQL\Language\AST\TypeSystemDefinitionNode TypeSystemDefinition : - SchemaDefinition - TypeDefinition - TypeExtensionDefinition - DirectiveDefinition
parseUnionMembers ( ) : NamedTypeNode[] UnionMembers : - NamedType - UnionMembers | NamedType
parseUnionTypeDefinition ( ) : UnionTypeDefinitionNode
parseValue ( Source | string $source, array $options = [] ) : BooleanValueNode | EnumValueNode | FloatValueNode | IntValueNode | ListValueNode | ObjectValueNode | StringValueNode | VariableNode Given a string containing a GraphQL value (ex. [42]), parse the AST for that value.
parseValueLiteral ( $isConst ) : BooleanValueNode | EnumValueNode | FloatValueNode | IntValueNode | StringValueNode | VariableNode | ListValueNode | ObjectValueNode | NullValueNode Value[Const] : - [~Const] Variable - IntValue - FloatValue - StringValue - BooleanValue - NullValue - EnumValue - ListValue[?Const] - ObjectValue[?Const]
parseVariable ( ) : VariableNode
parseVariableDefinition ( ) : VariableDefinitionNode
parseVariableDefinitions ( ) : VariableDefinitionNode[]
parseVariableValue ( ) : BooleanValueNode | EnumValueNode | FloatValueNode | IntValueNode | ListValueNode | ObjectValueNode | StringValueNode | VariableNode
peek ( $kind ) : boolean Determines if the next token is of a given kind
skip ( $kind ) : boolean If the next token is of the given kind, return true after advancing the parser. Otherwise, do not change the parser state and return false.
unexpected ( Token $atToken = null ) : SyntaxError

Method Details

__construct() public method

Parser constructor.
public __construct ( Source $source, array $options = [] )
$source Source
$options array

any() public method

Returns a possibly empty list of parse nodes, determined by the parseFn. This list begins with a lex token of openKind and ends with a lex token of closeKind. Advances the parser to the next lex token after the closing token.
public any ( integer $openKind, callable $parseFn, integer $closeKind ) : array
$openKind integer
$parseFn callable
$closeKind integer
return array

expect() public method

If the next token is of the given kind, return that token after advancing the parser. Otherwise, do not change the parser state and return false.
public expect ( string $kind ) : Token
$kind string
return Token

expectKeyword() public method

If the next token is a keyword with the given value, return that token after advancing the parser. Otherwise, do not change the parser state and return false.
public expectKeyword ( string $value ) : Token
$value string
return Token

loc() public method

Returns a location object, used to identify the place in the source that created a given parsed object.
public loc ( Token $startToken ) : Location | null
$startToken Token
return GraphQL\Language\AST\Location | null

many() public method

Returns a non-empty list of parse nodes, determined by the parseFn. This list begins with a lex token of openKind and ends with a lex token of closeKind. Advances the parser to the next lex token after the closing token.
public many ( $openKind, $parseFn, $closeKind ) : array
$openKind
$parseFn
$closeKind
return array

parse() public static method

noLocation: boolean, (By default, the parser creates AST nodes that know the location in the source that they correspond to. This configuration flag disables that behavior for performance or testing.)
public static parse ( Source | string $source, array $options = [] ) : DocumentNode
$source Source | string
$options array
return GraphQL\Language\AST\DocumentNode

parseArgument() public method

public parseArgument ( ) : ArgumentNode
return GraphQL\Language\AST\ArgumentNode

parseArgumentDefs() public method

public parseArgumentDefs ( ) : InputValueDefinitionNode[]
return GraphQL\Language\AST\InputValueDefinitionNode[]

parseArguments() public method

public parseArguments ( ) : ArgumentNode[]
return GraphQL\Language\AST\ArgumentNode[]

parseArray() public method

public parseArray ( boolean $isConst ) : ListValueNode
$isConst boolean
return GraphQL\Language\AST\ListValueNode

parseConstValue() public method

public parseConstValue ( ) : BooleanValueNode | EnumValueNode | FloatValueNode | IntValueNode | StringValueNode | VariableNode
return GraphQL\Language\AST\BooleanValueNode | GraphQL\Language\AST\EnumValueNode | GraphQL\Language\AST\FloatValueNode | GraphQL\Language\AST\IntValueNode | GraphQL\Language\AST\StringValueNode | GraphQL\Language\AST\VariableNode

parseDefinition() public method

public parseDefinition ( ) : OperationDefinitionNode | FragmentDefinitionNode | GraphQL\Language\AST\TypeSystemDefinitionNode
return GraphQL\Language\AST\OperationDefinitionNode | GraphQL\Language\AST\FragmentDefinitionNode | GraphQL\Language\AST\TypeSystemDefinitionNode

parseDirective() public method

public parseDirective ( ) : DirectiveNode
return GraphQL\Language\AST\DirectiveNode

parseDirectiveDefinition() public method

DirectiveDefinition : - directive @ Name ArgumentsDefinition? on DirectiveLocations
public parseDirectiveDefinition ( ) : DirectiveDefinitionNode
return GraphQL\Language\AST\DirectiveDefinitionNode

parseDirectiveLocations() public method

public parseDirectiveLocations ( ) : NameNode[]
return GraphQL\Language\AST\NameNode[]

parseDirectives() public method

public parseDirectives ( ) : DirectiveNode[]
return GraphQL\Language\AST\DirectiveNode[]

parseDocument() public method

Implements the parsing rules in the Document section.
public parseDocument ( ) : DocumentNode
return GraphQL\Language\AST\DocumentNode

parseEnumTypeDefinition() public method

public parseEnumTypeDefinition ( ) : EnumTypeDefinitionNode
return GraphQL\Language\AST\EnumTypeDefinitionNode

parseEnumValueDefinition() public method

public parseEnumValueDefinition ( ) : EnumValueDefinitionNode
return GraphQL\Language\AST\EnumValueDefinitionNode

parseField() public method

public parseField ( ) : FieldNode
return GraphQL\Language\AST\FieldNode

parseFieldDefinition() public method

public parseFieldDefinition ( ) : FieldDefinitionNode
return GraphQL\Language\AST\FieldDefinitionNode

parseFragment() public method

public parseFragment ( ) : FragmentSpreadNode | InlineFragmentNode
return GraphQL\Language\AST\FragmentSpreadNode | GraphQL\Language\AST\InlineFragmentNode

parseFragmentDefinition() public method

public parseFragmentDefinition ( ) : FragmentDefinitionNode
return GraphQL\Language\AST\FragmentDefinitionNode

parseFragmentName() public method

public parseFragmentName ( ) : NameNode
return GraphQL\Language\AST\NameNode

parseImplementsInterfaces() public method

public parseImplementsInterfaces ( ) : NamedTypeNode[]
return GraphQL\Language\AST\NamedTypeNode[]

parseInputObjectTypeDefinition() public method

public parseInputObjectTypeDefinition ( ) : InputObjectTypeDefinitionNode
return GraphQL\Language\AST\InputObjectTypeDefinitionNode

parseInputValueDef() public method

public parseInputValueDef ( ) : InputValueDefinitionNode
return GraphQL\Language\AST\InputValueDefinitionNode

parseInterfaceTypeDefinition() public method

public parseInterfaceTypeDefinition ( ) : InterfaceTypeDefinitionNode
return GraphQL\Language\AST\InterfaceTypeDefinitionNode

parseName() public method

Converts a name lex token into a name parse node.
public parseName ( ) : NameNode
return GraphQL\Language\AST\NameNode

parseNamedType() public method

public parseNamedType ( )

parseObject() public method

public parseObject ( $isConst ) : ObjectValueNode
$isConst
return GraphQL\Language\AST\ObjectValueNode

parseObjectField() public method

public parseObjectField ( $isConst ) : ObjectFieldNode
$isConst
return GraphQL\Language\AST\ObjectFieldNode

parseObjectTypeDefinition() public method

public parseObjectTypeDefinition ( ) : ObjectTypeDefinitionNode
return GraphQL\Language\AST\ObjectTypeDefinitionNode

parseOperationDefinition() public method

public parseOperationDefinition ( ) : OperationDefinitionNode
return GraphQL\Language\AST\OperationDefinitionNode

parseOperationType() public method

public parseOperationType ( ) : string
return string

parseOperationTypeDefinition() public method

public parseOperationTypeDefinition ( ) : OperationTypeDefinitionNode
return GraphQL\Language\AST\OperationTypeDefinitionNode

parseScalarTypeDefinition() public method

public parseScalarTypeDefinition ( ) : ScalarTypeDefinitionNode
return GraphQL\Language\AST\ScalarTypeDefinitionNode

parseSchemaDefinition() public method

public parseSchemaDefinition ( ) : SchemaDefinitionNode
return GraphQL\Language\AST\SchemaDefinitionNode

parseSelection() public method

Selection : - Field - FragmentSpread - InlineFragment
public parseSelection ( ) : mixed
return mixed

parseSelectionSet() public method

public parseSelectionSet ( ) : SelectionSetNode
return GraphQL\Language\AST\SelectionSetNode

parseType() public static method

Throws GraphQLError if a syntax error is encountered. This is useful within tools that operate upon GraphQL Types directly and in isolation of complete GraphQL documents. Consider providing the results to the utility function: typeFromAST().
public static parseType ( Source | string $source, array $options = [] ) : ListTypeNode | NameNode | NonNullTypeNode
$source Source | string
$options array
return GraphQL\Language\AST\ListTypeNode | GraphQL\Language\AST\NameNode | GraphQL\Language\AST\NonNullTypeNode

parseTypeExtensionDefinition() public method

public parseTypeExtensionDefinition ( ) : TypeExtensionDefinitionNode
return GraphQL\Language\AST\TypeExtensionDefinitionNode

parseTypeReference() public method

Handles the Type: TypeName, ListType, and NonNullType parsing rules.
public parseTypeReference ( ) : ListTypeNode | NameNode | NonNullTypeNode
return GraphQL\Language\AST\ListTypeNode | GraphQL\Language\AST\NameNode | GraphQL\Language\AST\NonNullTypeNode

parseTypeSystemDefinition() public method

TypeDefinition : - ScalarTypeDefinition - ObjectTypeDefinition - InterfaceTypeDefinition - UnionTypeDefinition - EnumTypeDefinition - InputObjectTypeDefinition
public parseTypeSystemDefinition ( ) : GraphQL\Language\AST\TypeSystemDefinitionNode
return GraphQL\Language\AST\TypeSystemDefinitionNode

parseUnionMembers() public method

UnionMembers : - NamedType - UnionMembers | NamedType
public parseUnionMembers ( ) : NamedTypeNode[]
return GraphQL\Language\AST\NamedTypeNode[]

parseUnionTypeDefinition() public method

public parseUnionTypeDefinition ( ) : UnionTypeDefinitionNode
return GraphQL\Language\AST\UnionTypeDefinitionNode

parseValue() public static method

Throws GraphQLError if a syntax error is encountered. This is useful within tools that operate upon GraphQL Values directly and in isolation of complete GraphQL documents. Consider providing the results to the utility function: valueFromAST().
public static parseValue ( Source | string $source, array $options = [] ) : BooleanValueNode | EnumValueNode | FloatValueNode | IntValueNode | ListValueNode | ObjectValueNode | StringValueNode | VariableNode
$source Source | string
$options array
return GraphQL\Language\AST\BooleanValueNode | GraphQL\Language\AST\EnumValueNode | GraphQL\Language\AST\FloatValueNode | GraphQL\Language\AST\IntValueNode | GraphQL\Language\AST\ListValueNode | GraphQL\Language\AST\ObjectValueNode | GraphQL\Language\AST\StringValueNode | GraphQL\Language\AST\VariableNode

parseValueLiteral() public method

BooleanValue : one of true false NullValue : null EnumValue : Name but not true, false or null
public parseValueLiteral ( $isConst ) : BooleanValueNode | EnumValueNode | FloatValueNode | IntValueNode | StringValueNode | VariableNode | ListValueNode | ObjectValueNode | NullValueNode
$isConst
return GraphQL\Language\AST\BooleanValueNode | GraphQL\Language\AST\EnumValueNode | GraphQL\Language\AST\FloatValueNode | GraphQL\Language\AST\IntValueNode | GraphQL\Language\AST\StringValueNode | GraphQL\Language\AST\VariableNode | GraphQL\Language\AST\ListValueNode | GraphQL\Language\AST\ObjectValueNode | GraphQL\Language\AST\NullValueNode

parseVariable() public method

public parseVariable ( ) : VariableNode
return GraphQL\Language\AST\VariableNode

parseVariableDefinition() public method

public parseVariableDefinition ( ) : VariableDefinitionNode
return GraphQL\Language\AST\VariableDefinitionNode

parseVariableDefinitions() public method

public parseVariableDefinitions ( ) : VariableDefinitionNode[]
return GraphQL\Language\AST\VariableDefinitionNode[]

parseVariableValue() public method

public parseVariableValue ( ) : BooleanValueNode | EnumValueNode | FloatValueNode | IntValueNode | ListValueNode | ObjectValueNode | StringValueNode | VariableNode
return GraphQL\Language\AST\BooleanValueNode | GraphQL\Language\AST\EnumValueNode | GraphQL\Language\AST\FloatValueNode | GraphQL\Language\AST\IntValueNode | GraphQL\Language\AST\ListValueNode | GraphQL\Language\AST\ObjectValueNode | GraphQL\Language\AST\StringValueNode | GraphQL\Language\AST\VariableNode

peek() public method

Determines if the next token is of a given kind
public peek ( $kind ) : boolean
$kind
return boolean

skip() public method

If the next token is of the given kind, return true after advancing the parser. Otherwise, do not change the parser state and return false.
public skip ( $kind ) : boolean
$kind
return boolean

unexpected() public method

public unexpected ( Token $atToken = null ) : SyntaxError
$atToken Token
return GraphQL\Error\SyntaxError