Options
All
  • Public
  • Public/Protected
  • All
Menu

Package graphql-language-service-parser

graphql-language-service-parser

NPM npm downloads License API Docs Discord Channel

An online immutable parser for GraphQL, designed to be used as part of syntax-highlighting and code intelligence tools such as for the GraphQL Language Service and codemirror-graphql.

Index

References

AdditionalRuleKinds

Re-exports AdditionalRuleKinds

CharacterStream

Re-exports CharacterStream

CharacterStreamInterface

Re-exports CharacterStreamInterface

ContextToken

Re-exports ContextToken

ContextTokenForCodeMirror

Re-exports ContextTokenForCodeMirror

ContextTokenUnion

Re-exports ContextTokenUnion

LexRules

Re-exports LexRules

ParseRule

Re-exports ParseRule

ParseRules

Re-exports ParseRules

ParserOptions

Re-exports ParserOptions

Rule

Re-exports Rule

RuleKind

Re-exports RuleKind

RuleKindEnum

Re-exports RuleKindEnum

RuleKinds

Re-exports RuleKinds

RuleOrString

Re-exports RuleOrString

State

Re-exports State

Token

Re-exports Token

TokenPattern

Re-exports TokenPattern

_AdditionalRuleKinds

Re-exports _AdditionalRuleKinds

_RuleKinds

Re-exports _RuleKinds

butNot

Re-exports butNot

isIgnored

Re-exports isIgnored

list

Re-exports list

onlineParser

Re-exports onlineParser

opt

Re-exports opt

p

Re-exports p

t

Re-exports t

Type aliases

ContextToken

ContextToken: { end: number; start: number; state: State; string: string; style?: string }

Type declaration

  • end: number
  • start: number
  • state: State
  • string: string
  • Optional style?: string

ContextTokenForCodeMirror

ContextTokenForCodeMirror: { end: number; start: number; state: State; string: string; type: string | null }

Type declaration

  • end: number
  • start: number
  • state: State
  • string: string
  • type: string | null

ContextTokenUnion

ParseRule

ParseRule: RuleOrString[] | ((token: Token, stream: CharacterStream) => string | null | void)

ParserOptions

ParserOptions: { eatWhitespace: (stream: CharacterStream) => boolean; editorConfig: {}; lexRules: Partial<typeof LexRulesType>; parseRules: typeof ParseRulesType }

Type declaration

  • eatWhitespace: (stream: CharacterStream) => boolean
  • editorConfig: {}
    • [name: string]: any
  • lexRules: Partial<typeof LexRulesType>
  • parseRules: typeof ParseRulesType

Rule

Rule: { isList?: boolean; match?: (token: Token) => boolean; ofRule?: Rule | string; separator?: string | Rule; style?: string; update?: (state: State, token: Token) => void }

Type declaration

  • Optional isList?: boolean
  • Optional match?: (token: Token) => boolean
      • (token: Token): boolean
      • Parameters

        Returns boolean

  • Optional ofRule?: Rule | string
  • Optional separator?: string | Rule
  • Optional style?: string
  • Optional update?: (state: State, token: Token) => void

RuleKind

RuleKind: _RuleKinds[keyof _RuleKinds]

RuleKindEnum

RuleKindEnum: RuleKind

RuleOrString

RuleOrString: Rule | string

State

State: { indentLevel?: number; kind: Maybe<RuleKind>; level: number; levels?: number[]; name: Maybe<string>; needsAdvance?: boolean; needsSeperator: boolean; prevState: Maybe<State>; rule: Maybe<ParseRule>; step: number; type: Maybe<string> }

Type declaration

  • Optional indentLevel?: number
  • kind: Maybe<RuleKind>
  • level: number
  • Optional levels?: number[]
  • name: Maybe<string>
  • Optional needsAdvance?: boolean
  • needsSeperator: boolean
  • prevState: Maybe<State>
  • rule: Maybe<ParseRule>
  • step: number
  • type: Maybe<string>

Token

Token: { kind: string; value: string }

Type declaration

  • kind: string
  • value: string

TokenPattern

TokenPattern: string | ((char: string) => boolean) | RegExp

_AdditionalRuleKinds

_AdditionalRuleKinds: { ALIASED_FIELD: "AliasedField"; ARGUMENTS: "Arguments"; ARGUMENTS_DEF: "ArgumentsDef"; COMMENT: "Comment"; DIRECTIVE_DEF: "DirectiveDef"; ENUM_DEF: "EnumDef"; ENUM_VALUE: "EnumValue"; EXTEND_DEF: "ExtendDef"; FIELD_DEF: "FieldDef"; IMPLEMENTS: "Implements"; INPUT_DEF: "InputDef"; INPUT_VALUE_DEF: "InputValueDef"; INTERFACE_DEF: "InterfaceDef"; INVALID: "Invalid"; LIST_VALUE: "ListValue"; MUTATION: "Mutation"; OBJECT_TYPE_DEF: "ObjectTypeDef"; OBJECT_VALUE: "ObjectValue"; QUERY: "Query"; SCALAR_DEF: "ScalarDef"; SCHEMA_DEF: "SchemaDef"; SHORT_QUERY: "ShortQuery"; SUBSCRIPTION: "Subscription"; TYPE: "Type"; TYPE_CONDITION: "TypeCondition"; UNION_DEF: "UnionDef"; VARIABLE_DEFINITIONS: "VariableDefinitions" }

Type declaration

  • ALIASED_FIELD: "AliasedField"
  • ARGUMENTS: "Arguments"
  • ARGUMENTS_DEF: "ArgumentsDef"
  • COMMENT: "Comment"
  • DIRECTIVE_DEF: "DirectiveDef"
  • ENUM_DEF: "EnumDef"
  • ENUM_VALUE: "EnumValue"
  • EXTEND_DEF: "ExtendDef"
  • FIELD_DEF: "FieldDef"
  • IMPLEMENTS: "Implements"
  • INPUT_DEF: "InputDef"
  • INPUT_VALUE_DEF: "InputValueDef"
  • INTERFACE_DEF: "InterfaceDef"
  • INVALID: "Invalid"
  • LIST_VALUE: "ListValue"
  • MUTATION: "Mutation"
  • OBJECT_TYPE_DEF: "ObjectTypeDef"
  • OBJECT_VALUE: "ObjectValue"
  • QUERY: "Query"
  • SCALAR_DEF: "ScalarDef"
  • SCHEMA_DEF: "SchemaDef"
  • SHORT_QUERY: "ShortQuery"
  • SUBSCRIPTION: "Subscription"
  • TYPE: "Type"
  • TYPE_CONDITION: "TypeCondition"
  • UNION_DEF: "UnionDef"
  • VARIABLE_DEFINITIONS: "VariableDefinitions"

_RuleKinds

_RuleKinds: typeof Kind & typeof AdditionalRuleKinds

Functions

butNot

  • Parameters

    Returns Rule

Const isIgnored

  • isIgnored(ch: string): boolean
  • Whitespace tokens defined in GraphQL spec.

    Parameters

    • ch: string

    Returns boolean

list

  • list(ofRule: Rule | string, separator?: string | Rule): Rule
  • Parameters

    • ofRule: Rule | string
    • Optional separator: string | Rule

    Returns Rule

onlineParser

opt

  • Parameters

    • ofRule: Rule | string

    Returns Rule

p

  • p(value: string, style?: string): Rule
  • Parameters

    • value: string
    • Optional style: string

    Returns Rule

t

  • t(kind: string, style: string): { style: string; match: any }
  • Parameters

    • kind: string
    • style: string

    Returns { style: string; match: any }

    • style: string
    • match: function
      • match(token: Token): boolean
      • Parameters

        Returns boolean

Object literals

Const AdditionalRuleKinds

AdditionalRuleKinds: object

ALIASED_FIELD

ALIASED_FIELD: "AliasedField" = "AliasedField"

ARGUMENTS

ARGUMENTS: "Arguments" = "Arguments"

ARGUMENTS_DEF

ARGUMENTS_DEF: "ArgumentsDef" = "ArgumentsDef"

COMMENT

COMMENT: "Comment" = "Comment"

DIRECTIVE_DEF

DIRECTIVE_DEF: "DirectiveDef" = "DirectiveDef"

ENUM_DEF

ENUM_DEF: "EnumDef" = "EnumDef"

ENUM_VALUE

ENUM_VALUE: "EnumValue" = "EnumValue"

EXTEND_DEF

EXTEND_DEF: "ExtendDef" = "ExtendDef"

FIELD_DEF

FIELD_DEF: "FieldDef" = "FieldDef"

IMPLEMENTS

IMPLEMENTS: "Implements" = "Implements"

INPUT_DEF

INPUT_DEF: "InputDef" = "InputDef"

INPUT_VALUE_DEF

INPUT_VALUE_DEF: "InputValueDef" = "InputValueDef"

INTERFACE_DEF

INTERFACE_DEF: "InterfaceDef" = "InterfaceDef"

INVALID

INVALID: "Invalid" = "Invalid"

LIST_VALUE

LIST_VALUE: "ListValue" = "ListValue"

MUTATION

MUTATION: "Mutation" = "Mutation"

OBJECT_TYPE_DEF

OBJECT_TYPE_DEF: "ObjectTypeDef" = "ObjectTypeDef"

OBJECT_VALUE

OBJECT_VALUE: "ObjectValue" = "ObjectValue"

QUERY

QUERY: "Query" = "Query"

SCALAR_DEF

SCALAR_DEF: "ScalarDef" = "ScalarDef"

SCHEMA_DEF

SCHEMA_DEF: "SchemaDef" = "SchemaDef"

SHORT_QUERY

SHORT_QUERY: "ShortQuery" = "ShortQuery"

SUBSCRIPTION

SUBSCRIPTION: "Subscription" = "Subscription"

TYPE

TYPE: "Type" = "Type"

TYPE_CONDITION

TYPE_CONDITION: "TypeCondition" = "TypeCondition"

UNION_DEF

UNION_DEF: "UnionDef" = "UnionDef"

VARIABLE_DEFINITIONS

VARIABLE_DEFINITIONS: "VariableDefinitions" = "VariableDefinitions"

Const LexRules

LexRules: object

The lexer rules. These are exactly as described by the spec.

Comment

Comment: RegExp = /^#.*/

Name

Name: RegExp = /^[_A-Za-z][_0-9A-Za-z]*/

Number

Number: RegExp = /^-?(?:0|(?:[1-9][0-9]*))(?:\.[0-9]*)?(?:[eE][+-]?[0-9]+)?/

Punctuation

Punctuation: RegExp = /^(?:!|\$|\(|\)|\.\.\.|:|=|&|@|\[|]|\{|\||\})/

String

String: RegExp = /^(?:"""(?:\\"""|[^"]|"[^"]|""[^"])*(?:""")?|"(?:[^"\\]|\\(?:"|\/|\\|b|f|n|r|t|u[0-9a-fA-F]{4}))*"?)/

Const ParseRules

ParseRules: object

The parser rules. These are very close to, but not exactly the same as the spec. Minor deviations allow for a simpler implementation. The resulting parser can parse everything the spec declares possible.

AliasedField

AliasedField: Rule[] = [name('property'),p(':'),name('qualifier'),opt('Arguments'),list('Directive'),opt('SelectionSet'),]

Argument

Argument: RuleOrString[] = [name('attribute'), p(':'), 'Value']

Arguments

Arguments: Rule[] = [p('('), list('Argument'), p(')')]

ArgumentsDef

ArgumentsDef: Rule[] = [p('('), list('InputValueDef'), p(')')]

BooleanValue

BooleanValue: { style: string; match: any }[] = [t('Name', 'builtin')]

DefaultValue

DefaultValue: RuleOrString[] = [p('='), 'Value']

Directive

Directive: Rule[] = [p('@', 'meta'), name('meta'), opt('Arguments')]

DirectiveDef

DirectiveDef: (Rule | { style: string; match: any })[] = [word('directive'),p('@', 'meta'),name('meta'),opt('ArgumentsDef'),word('on'),list('DirectiveLocation', p('|')),]

DirectiveLocation

DirectiveLocation: Rule[] = [name('string-2')]

Document

Document: Rule[] = [list('Definition')]

EnumDef

EnumDef: (Rule | { style: string; match: any })[] = [word('enum'),name('atom'),list('Directive'),p('{'),list('EnumValueDef'),p('}'),]

EnumValue

EnumValue: Rule[] = [name('string-2')]

EnumValueDef

EnumValueDef: Rule[] = [name('string-2'), list('Directive')]

ExtendDef

ExtendDef: (string | { style: string; match: any })[] = [word('extend'), 'ObjectTypeDef']

Field

Field: Rule[] = [name('property'),opt('Arguments'),list('Directive'),opt('SelectionSet'),]

FieldDef

FieldDef: RuleOrString[] = [name('property'),opt('ArgumentsDef'),p(':'),'Type',list('Directive'),]

FragmentDefinition

FragmentDefinition: (string | Rule | { style: string; match: any })[] = [word('fragment'),opt(butNot(name('def'), [word('on')])),'TypeCondition',list('Directive'),'SelectionSet',]

FragmentSpread

FragmentSpread: Rule[] = [p('...'), name('def'), list('Directive')]

Implements

Implements: (Rule | { style: string; match: any })[] = [word('implements'), list('NamedType', p('&'))]

InlineFragment

InlineFragment: RuleOrString[] = [p('...'),opt('TypeCondition'),list('Directive'),'SelectionSet',]

InputDef

InputDef: (Rule | { style: string; match: any })[] = [word('input'),name('atom'),list('Directive'),p('{'),list('InputValueDef'),p('}'),]

InputValueDef

InputValueDef: RuleOrString[] = [name('attribute'),p(':'),'Type',opt('DefaultValue'),list('Directive'),]

InterfaceDef

InterfaceDef: (Rule | { style: string; match: any })[] = [word('interface'),name('atom'),opt('Implements'),list('Directive'),p('{'),list('FieldDef'),p('}'),]

ListType

ListType: RuleOrString[] = [p('['), 'Type', p(']'), opt(p('!'))]

ListValue

ListValue: Rule[] = [p('['), list('Value'), p(']')]

Mutation

Mutation: (string | Rule | { style: string; match: any })[] = [word('mutation'),opt(name('def')),opt('VariableDefinitions'),list('Directive'),'SelectionSet',]

NamedType

NamedType: { style: string; match: any; update: any }[] = [type('atom')]

NonNullType

NonNullType: RuleOrString[] = ['NamedType', opt(p('!'))]

NullValue

NullValue: { style: string; match: any }[] = [t('Name', 'keyword')]

NumberValue

NumberValue: { style: string; match: any }[] = [t('Number', 'number')]

ObjectField

ObjectField: RuleOrString[] = [name('attribute'), p(':'), 'Value']

ObjectTypeDef

ObjectTypeDef: (Rule | { style: string; match: any })[] = [word('type'),name('atom'),opt('Implements'),list('Directive'),p('{'),list('FieldDef'),p('}'),]

ObjectValue

ObjectValue: Rule[] = [p('{'), list('ObjectField'), p('}')]

OperationTypeDef

OperationTypeDef: Rule[] = [name('keyword'), p(':'), name('atom')]

Query

Query: (string | Rule | { style: string; match: any })[] = [word('query'),opt(name('def')),opt('VariableDefinitions'),list('Directive'),'SelectionSet',]

ScalarDef

ScalarDef: (Rule | { style: string; match: any })[] = [word('scalar'), name('atom'), list('Directive')]

SchemaDef

SchemaDef: (Rule | { style: string; match: any })[] = [word('schema'),list('Directive'),p('{'),list('OperationTypeDef'),p('}'),]

SelectionSet

SelectionSet: Rule[] = [p('{'), list('Selection'), p('}')]

ShortQuery

ShortQuery: string[] = ['SelectionSet']

StringValue

StringValue: { style: string; match: any }[] = [t('String', 'string')]

Subscription

Subscription: (string | Rule | { style: string; match: any })[] = [word('subscription'),opt(name('def')),opt('VariableDefinitions'),list('Directive'),'SelectionSet',]

TypeCondition

TypeCondition: (string | { style: string; match: any })[] = [word('on'), 'NamedType']

UnionDef

UnionDef: (Rule | { style: string; match: any })[] = [word('union'),name('atom'),list('Directive'),p('='),list('UnionMember', p('|')),]

UnionMember

UnionMember: string[] = ['NamedType']

Variable

Variable: Rule[] = [p('$', 'variable'), name('variable')]

VariableDefinition

VariableDefinition: RuleOrString[] = ['Variable', p(':'), 'Type', opt('DefaultValue')]

VariableDefinitions

VariableDefinitions: Rule[] = [p('('), list('VariableDefinition'), p(')')]

Definition

  • Parameters

    Returns RuleKind | void

Selection

  • Selection(token: Token, stream: CharacterStream): "Field" | "FragmentSpread" | "InlineFragment" | "AliasedField"
  • Parameters

    Returns "Field" | "FragmentSpread" | "InlineFragment" | "AliasedField"

Type

  • Type(token: Token): "ListType" | "NonNullType"
  • Parameters

    Returns "ListType" | "NonNullType"

Value

  • Value(token: Token): "EnumValue" | "Variable" | "StringValue" | "BooleanValue" | "NullValue" | "ListValue" | "ObjectValue" | "NamedType" | "NumberValue"
  • Parameters

    Returns "EnumValue" | "Variable" | "StringValue" | "BooleanValue" | "NullValue" | "ListValue" | "ObjectValue" | "NamedType" | "NumberValue"

Const RuleKinds

RuleKinds: object

Generated using TypeDoc