Options
All
  • Public
  • Public/Protected
  • All
Menu

Package graphql-language-service

graphql-language-service

Changelog | API Docs | Discord

Note: Still mostly experimental, however it depends mostly on stable libraries. Migration Note: As of 3.0.0, the LSP Server command line interface has been moved to graphql-language-service-cli

Purpose

This package brings together all the dependencies for building out web or desktop IDE services for the GraphQL Language.

It is named as such to match the convention of other vscode language services.

Interface

Language Service Protocol (LSP) methods written in TypeScript used by graphql-language-service-server, monaco-graphql and codemirror-graphql.

The goal is to provide methods for creating Language Server Protocol compliant services to be used by an IDE plugin, a browser application or desktop application.

Parser

A standalone online, immutable, dependency-free parser for GraphQL, used by the LSP interface methods

Utils

Various utilities

Index

References

Namespaces

Enumerations

Classes

Interfaces

Type aliases

Variables

Functions

Object literals

References

AdditionalRuleKinds

Re-exports AdditionalRuleKinds

AutocompleteSuggestionOptions

Re-exports AutocompleteSuggestionOptions

AutocompleteSuggestionOptions

Re-exports AutocompleteSuggestionOptions

CachedContent

Re-exports CachedContent

CharacterStream

Re-exports CharacterStream

CharacterStream

Re-exports CharacterStream

CharacterStreamInterface

Re-exports CharacterStreamInterface

CharacterStreamInterface

Re-exports CharacterStreamInterface

CompletionItem

Re-exports CompletionItem

CompletionItemKind

Re-exports CompletionItemKind

ContextToken

Re-exports ContextToken

ContextToken

Re-exports ContextToken

ContextTokenForCodeMirror

Re-exports ContextTokenForCodeMirror

ContextTokenForCodeMirror

Re-exports ContextTokenForCodeMirror

ContextTokenUnion

Re-exports ContextTokenUnion

ContextTokenUnion

Re-exports ContextTokenUnion

DIAGNOSTIC_SEVERITY

Re-exports DIAGNOSTIC_SEVERITY

DIAGNOSTIC_SEVERITY

Re-exports DIAGNOSTIC_SEVERITY

Definition

Re-exports Definition

DefinitionQueryResult

Re-exports DefinitionQueryResult

DefinitionQueryResult

Re-exports DefinitionQueryResult

Diagnostic

Re-exports Diagnostic

FileChangeType

Re-exports FileChangeType

FileChangeTypeKind

Re-exports FileChangeTypeKind

FragmentInfo

Re-exports FragmentInfo

GraphQLCache

Re-exports GraphQLCache

GraphQLConfig

Re-exports GraphQLConfig

GraphQLDocumentMode

Re-exports GraphQLDocumentMode

GraphQLExtensionDeclaration

Re-exports GraphQLExtensionDeclaration

GraphQLFileInfo

Re-exports GraphQLFileInfo

GraphQLFileMetadata

Re-exports GraphQLFileMetadata

GraphQLProjectConfig

Re-exports GraphQLProjectConfig

HoverConfig

Re-exports HoverConfig

HoverConfig

Re-exports HoverConfig

IPosition

Re-exports IPosition

IRange

Re-exports IRange

InsertTextFormat

Re-exports InsertTextFormat

JSONSchema6

Re-exports JSONSchema6

JSONSchema6

Re-exports JSONSchema6

JSONSchema6TypeName

Re-exports JSONSchema6TypeName

JSONSchema6TypeName

Re-exports JSONSchema6TypeName

JSONSchemaOptions

Re-exports JSONSchemaOptions

JSONSchemaOptions

Re-exports JSONSchemaOptions

LANGUAGE

Re-exports LANGUAGE

LexRules

Re-exports LexRules

LexRules

Re-exports LexRules

Maybe

Re-exports Maybe

ObjectTypeInfo

Re-exports ObjectTypeInfo

OperationFacts

Re-exports OperationFacts

OperationFacts

Re-exports OperationFacts

Outline

Re-exports Outline

OutlineTree

Re-exports OutlineTree

ParseRule

Re-exports ParseRule

ParseRule

Re-exports ParseRule

ParseRules

Re-exports ParseRules

ParseRules

Re-exports ParseRules

ParserOptions

Re-exports ParserOptions

ParserOptions

Re-exports ParserOptions

Position

Re-exports Position

Position

Re-exports Position

QueryFacts

Re-exports QueryFacts

QueryFacts

Re-exports QueryFacts

Range

Re-exports Range

Range

Re-exports Range

Rule

Re-exports Rule

RuleKind

Re-exports RuleKind

RuleKind

Re-exports RuleKind

RuleKindEnum

Re-exports RuleKindEnum

RuleKindEnum

Re-exports RuleKindEnum

RuleKinds

Re-exports RuleKinds

RuleKinds

Re-exports RuleKinds

RuleOrString

Re-exports RuleOrString

RuleOrString

Re-exports RuleOrString

SEVERITY

Re-exports SEVERITY

SEVERITY

Re-exports SEVERITY

Severity

Re-exports Severity

Severity

Re-exports Severity

SeverityEnum

Re-exports SeverityEnum

SeverityEnum

Re-exports SeverityEnum

State

Re-exports State

State

Re-exports State

SuggestionCommand

Re-exports SuggestionCommand

SuggestionCommand

Re-exports SuggestionCommand

Token

Re-exports Token

Token

Re-exports Token

TokenPattern

Re-exports TokenPattern

TokenPattern

Re-exports TokenPattern

Uri

Re-exports Uri

VariableToType

Re-exports VariableToType

VariableToType

Re-exports VariableToType

_AdditionalRuleKinds

Re-exports _AdditionalRuleKinds

_RuleKinds

Re-exports _RuleKinds

butNot

Re-exports butNot

canUseDirective

Re-exports canUseDirective

canUseDirective

Re-exports canUseDirective

collectVariables

Re-exports collectVariables

collectVariables

Re-exports collectVariables

forEachState

Re-exports forEachState

getASTNodeAtPosition

Re-exports getASTNodeAtPosition

getASTNodeAtPosition

Re-exports getASTNodeAtPosition

getAutocompleteSuggestions

Re-exports getAutocompleteSuggestions

getAutocompleteSuggestions

Re-exports getAutocompleteSuggestions

getDefinitionQueryResultForDefinitionNode

Re-exports getDefinitionQueryResultForDefinitionNode

getDefinitionQueryResultForDefinitionNode

Re-exports getDefinitionQueryResultForDefinitionNode

getDefinitionQueryResultForField

Re-exports getDefinitionQueryResultForField

getDefinitionQueryResultForField

Re-exports getDefinitionQueryResultForField

getDefinitionQueryResultForFragmentSpread

Re-exports getDefinitionQueryResultForFragmentSpread

getDefinitionQueryResultForFragmentSpread

Re-exports getDefinitionQueryResultForFragmentSpread

getDefinitionQueryResultForNamedType

Re-exports getDefinitionQueryResultForNamedType

getDefinitionQueryResultForNamedType

Re-exports getDefinitionQueryResultForNamedType

getDefinitionState

Re-exports getDefinitionState

getDefinitionState

Re-exports getDefinitionState

getDiagnostics

Re-exports getDiagnostics

getDiagnostics

Re-exports getDiagnostics

getFieldDef

Re-exports getFieldDef

getFieldDef

Re-exports getFieldDef

getFragmentDefinitions

Re-exports getFragmentDefinitions

getFragmentDefinitions

Re-exports getFragmentDefinitions

getFragmentDependencies

Re-exports getFragmentDependencies

getFragmentDependencies

Re-exports getFragmentDependencies

getFragmentDependenciesForAST

Re-exports getFragmentDependenciesForAST

getFragmentDependenciesForAST

Re-exports getFragmentDependenciesForAST

getHoverInformation

Re-exports getHoverInformation

getHoverInformation

Re-exports getHoverInformation

getOperationASTFacts

Re-exports getOperationASTFacts

getOperationASTFacts

Re-exports getOperationASTFacts

getOperationFacts

Re-exports getOperationFacts

getOperationFacts

Re-exports getOperationFacts

getOutline

Re-exports getOutline

getOutline

Re-exports getOutline

getQueryFacts

Re-exports getQueryFacts

getQueryFacts

Re-exports getQueryFacts

getRange

Re-exports getRange

getRange

Re-exports getRange

getTokenAtPosition

Re-exports getTokenAtPosition

getTokenAtPosition

Re-exports getTokenAtPosition

getTypeInfo

Re-exports getTypeInfo

getTypeInfo

Re-exports getTypeInfo

getVariableCompletions

Re-exports getVariableCompletions

getVariableCompletions

Re-exports getVariableCompletions

getVariablesJSONSchema

Re-exports getVariablesJSONSchema

getVariablesJSONSchema

Re-exports getVariablesJSONSchema

hintList

Re-exports hintList

isIgnored

Re-exports isIgnored

isIgnored

Re-exports isIgnored

list

Re-exports list

list

Re-exports list

locToRange

Re-exports locToRange

objectValues

Re-exports objectValues

offsetToPosition

Re-exports offsetToPosition

offsetToPosition

Re-exports offsetToPosition

onlineParser

Re-exports onlineParser

onlineParser

Re-exports onlineParser

opt

Re-exports opt

opt

Re-exports opt

p

Re-exports p

p

Re-exports p

pointToOffset

Re-exports pointToOffset

pointToOffset

Re-exports pointToOffset

runOnlineParser

Re-exports runOnlineParser

t

Re-exports t

t

Re-exports t

validateQuery

Re-exports validateQuery

validateQuery

Re-exports validateQuery

validateWithCustomRules

Re-exports validateWithCustomRules

validateWithCustomRules

Re-exports validateWithCustomRules

Type aliases

AllTypeInfo

AllTypeInfo: { argDef: Maybe<GraphQLArgument>; argDefs: Maybe<GraphQLArgument[]>; directiveDef: Maybe<GraphQLDirective>; enumValue: Maybe<GraphQLEnumValue>; fieldDef: Maybe<GraphQLField<any, any>>; inputType: Maybe<GraphQLType>; interfaceDef: Maybe<GraphQLInterfaceType>; objectFieldDefs: Maybe<GraphQLInputFieldMap>; objectTypeDef: Maybe<GraphQLObjectType>; parentType: Maybe<GraphQLType>; type: Maybe<GraphQLType> }

Type declaration

  • argDef: Maybe<GraphQLArgument>
  • argDefs: Maybe<GraphQLArgument[]>
  • directiveDef: Maybe<GraphQLDirective>
  • enumValue: Maybe<GraphQLEnumValue>
  • fieldDef: Maybe<GraphQLField<any, any>>
  • inputType: Maybe<GraphQLType>
  • interfaceDef: Maybe<GraphQLInterfaceType>
  • objectFieldDefs: Maybe<GraphQLInputFieldMap>
  • objectTypeDef: Maybe<GraphQLObjectType>
  • parentType: Maybe<GraphQLType>
  • type: Maybe<GraphQLType>

AutocompleteSuggestionOptions

AutocompleteSuggestionOptions: { fillLeafsOnComplete?: undefined | false | true; mode?: GraphQLDocumentMode; schema?: GraphQLSchema; uri?: undefined | string }

Type declaration

  • Optional fillLeafsOnComplete?: undefined | false | true
  • Optional mode?: GraphQLDocumentMode
  • Optional schema?: GraphQLSchema
  • Optional uri?: undefined | string

CachedContent

CachedContent: { query: string; range: IRange | null }

Type declaration

  • query: string
  • range: IRange | null

CombinedSchema

CombinedSchema: JSONSchema6 | MonacoEditorJSONSchema

CompletionItem

CompletionItem: CompletionItemType & { command?: CompletionItemType["command"]; deprecationReason?: string | null; documentation?: string | null; isDeprecated?: undefined | false | true; type?: GraphQLType }

CompletionItemBase

CompletionItemBase: { isDeprecated?: undefined | false | true; label: string }

Type declaration

  • Optional isDeprecated?: undefined | false | true
  • label: string

ContextToken

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

Type declaration

  • end: number
  • start: number
  • state: State
  • string: string
  • Optional style?: undefined | 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

Definition

Definition: { id?: undefined | string; language?: undefined | string; name?: undefined | string; path: Uri; position: IPosition; projectRoot?: Uri; range?: IRange }

Type declaration

  • Optional id?: undefined | string
  • Optional language?: undefined | string
  • Optional name?: undefined | string
  • path: Uri
  • position: IPosition
  • Optional projectRoot?: Uri
  • Optional range?: IRange

DefinitionQueryResult

DefinitionQueryResult: { definitions: Definition[]; queryRange: Range[] }

Type declaration

DefinitionResult

DefinitionResult: { definition: JSONSchema6 | MonacoEditorJSONSchema; definitions?: Definitions; required: boolean }

Type declaration

Diagnostic

Diagnostic: DiagnosticType

FileChangeType

FileChangeType: FileChangeTypeKind[FileChangeTypeKeys]

FileChangeTypeKeys

FileChangeTypeKeys: keyof FileChangeTypeKind

FileChangeTypeKind

FileChangeTypeKind: { Changed: 2; Created: 1; Deleted: 3 }

Type declaration

  • Changed: 2
  • Created: 1
  • Deleted: 3

FragmentInfo

FragmentInfo: { content: string; definition: FragmentDefinitionNode; filePath?: Uri }

Type declaration

  • content: string
  • definition: FragmentDefinitionNode
  • Optional filePath?: Uri

GraphQLFileInfo

GraphQLFileInfo: { asts: DocumentNode[]; content: string; filePath: Uri; mtime: number; queries: CachedContent[]; size: number }

Type declaration

  • asts: DocumentNode[]
  • content: string
  • filePath: Uri
  • mtime: number
  • queries: CachedContent[]
  • size: number

GraphQLFileMetadata

GraphQLFileMetadata: { filePath: Uri; mtime: number; size: number }

Type declaration

  • filePath: Uri
  • mtime: number
  • size: number

HoverConfig

HoverConfig: { useMarkdown?: undefined | false | true }

Type declaration

  • Optional useMarkdown?: undefined | false | true

JSONSchemaOptions

JSONSchemaOptions: { scalarSchemas?: Record<string, JSONSchema6>; useMarkdownDescription?: undefined | false | true }

Type declaration

  • Optional scalarSchemas?: Record<string, JSONSchema6>

    Scalar schema mappings.

  • Optional useMarkdownDescription?: undefined | false | true

    whether to append a non-json schema valid 'markdownDescriptionformonaco-json`

JsonSchemaOptions

JsonSchemaOptions: { useMarkdownDescription?: undefined | false | true }

Type declaration

  • Optional useMarkdownDescription?: undefined | false | true

    use undocumented monaco-json markdownDescription field in place of json-schema spec description field.

Maybe

Maybe<T>: T | null | undefined

Type parameters

  • T

MonacoEditorJSONSchema

MonacoEditorJSONSchema: JSONSchema6 & { markdownDescription?: undefined | string }

NamedTypeInfo

NamedTypeInfo: { content: string; definition: NamedTypeNode; filePath?: Uri }

Type declaration

  • content: string
  • definition: NamedTypeNode
  • Optional filePath?: Uri

ObjectTypeInfo

ObjectTypeInfo: { content: string; definition: TypeDefinitionNode; filePath?: Uri }

Type declaration

  • content: string
  • definition: TypeDefinitionNode
  • Optional filePath?: Uri

OperationASTFacts

OperationASTFacts: { operations: OperationDefinitionNode[]; variableToType?: VariableToType }

Type declaration

  • operations: OperationDefinitionNode[]
  • Optional variableToType?: VariableToType

OperationFacts

OperationFacts: { documentAST: DocumentNode } & OperationASTFacts

Outline

Outline: { outlineTrees: OutlineTree[] }

Type declaration

OutlineTree

OutlineTree: { children: OutlineTree[]; endPosition?: IPosition; kind: string; plainText?: undefined | string; representativeName?: undefined | string; startPosition: IPosition; tokenizedText?: TokenizedText }

Type declaration

  • children: OutlineTree[]
  • Optional endPosition?: IPosition
  • kind: string
  • Optional plainText?: undefined | string
  • Optional representativeName?: undefined | string
  • startPosition: IPosition
  • Optional tokenizedText?: TokenizedText

OutlineableKinds

OutlineableKinds: keyof typeof OUTLINEABLE_KINDS

ParseRule

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

ParserOptions

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

Type declaration

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

QueryFacts

QueryFacts: OperationFacts

Rule

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

Type declaration

  • Optional isList?: undefined | false | true
  • Optional match?: undefined | ((token: Token) => boolean)
  • Optional ofRule?: Rule | string
  • Optional separator?: string | Rule
  • Optional style?: undefined | string
  • Optional update?: undefined | ((state: State, token: Token) => void)

RuleKind

RuleKind: _RuleKinds[keyof _RuleKinds]

RuleKindEnum

RuleKindEnum: RuleKind

RuleOrString

RuleOrString: Rule | string

Severity

Severity: typeof SEVERITY

SeverityEnum

SeverityEnum: keyof Severity

State

State: { inBlockstring?: undefined | false | true; indentLevel?: undefined | number; kind: Maybe<RuleKind>; level: number; levels?: number[]; name: Maybe<string>; needsAdvance?: undefined | false | true; needsSeparator: boolean; prevState: Maybe<State>; rule: Maybe<ParseRule>; step: number; type: Maybe<string> }

Type declaration

  • Optional inBlockstring?: undefined | false | true
  • Optional indentLevel?: undefined | number
  • kind: Maybe<RuleKind>
  • level: number
  • Optional levels?: number[]
  • name: Maybe<string>
  • Optional needsAdvance?: undefined | false | true
  • needsSeparator: boolean
  • prevState: Maybe<State>
  • rule: Maybe<ParseRule>
  • step: number
  • type: Maybe<string>

TextToken

TextToken: { kind: TokenKind; value: string | NameNode }

Type declaration

Token

Token: { kind: string; value: string }

Type declaration

  • kind: string
  • value: string

TokenKind

TokenKind: "keyword" | "class-name" | "constructor" | "method" | "param" | "string" | "whitespace" | "plain" | "type"

TokenPattern

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

TokenizedText

TokenizedText: TextToken[]

Uri

Uri: string

VariableToType

VariableToType: {}

Type declaration

  • [variable: string]: GraphQLInputType

_AdditionalRuleKinds

_AdditionalRuleKinds: { ALIASED_FIELD: "AliasedField"; ARGUMENTS: "Arguments"; ARGUMENTS_DEF: "ArgumentsDef"; COMMENT: "Comment"; DIRECTIVE_DEF: "DirectiveDef"; ENUM_DEF: "EnumDef"; ENUM_VALUE: "EnumValue"; EXTEND_DEF: "ExtendDef"; EXTENSION_DEFINITION: "ExtensionDefinition"; 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"
  • EXTENSION_DEFINITION: "ExtensionDefinition"
  • 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

Variables

Const LANGUAGE

LANGUAGE: "GraphQL" = "GraphQL"

Const SEVERITY

SEVERITY: { Error: "Error"; Hint: "Hint"; Information: "Information"; Warning: "Warning" } = {Error: 'Error',Warning: 'Warning',Information: 'Information',Hint: 'Hint',} as const

Type declaration

  • Error: "Error"
  • Hint: "Hint"
  • Information: "Information"
  • Warning: "Warning"

Const getQueryFacts

getQueryFacts: getOperationFacts = getOperationFacts

for backwards compatibility

Functions

bright

  • bright(str: string): string

butNot

canUseDirective

  • canUseDirective(state: State["prevState"], directive: GraphQLDirective): boolean

collectVariables

  • collectVariables(schema: GraphQLSchema, documentAST: DocumentNode): VariableToType

forEachState

getASTNodeAtPosition

  • getASTNodeAtPosition(query: string, ast: ASTNode, point: TPosition): ASTNode | undefined

getAutocompleteSuggestions

getDefinitionQueryResultForDefinitionNode

  • getDefinitionQueryResultForDefinitionNode(path: Uri, text: string, definition: FragmentDefinitionNode | OperationDefinitionNode): DefinitionQueryResult

getDefinitionQueryResultForField

getDefinitionQueryResultForFragmentSpread

getDefinitionQueryResultForNamedType

getDefinitionState

  • getDefinitionState(tokenState: State): State | null | undefined

getDiagnostics

  • getDiagnostics(query: string, schema?: GraphQLSchema | null | undefined, customRules?: Array<ValidationRule>, isRelayCompatMode?: undefined | false | true, externalFragments?: FragmentDefinitionNode[] | string): Array<Diagnostic>
  • Parameters

    • query: string
    • Default value schema: GraphQLSchema | null | undefined = null
    • Optional customRules: Array<ValidationRule>
    • Optional isRelayCompatMode: undefined | false | true
    • Optional externalFragments: FragmentDefinitionNode[] | string

    Returns Array<Diagnostic>

getFieldDef

  • getFieldDef(schema: GraphQLSchema, type: GraphQLType, fieldName: string): GraphQLField<any, any> | null | undefined

getFragmentDefinitions

  • getFragmentDefinitions(queryText: string): Array<FragmentDefinitionNode>

Const getFragmentDependencies

  • getFragmentDependencies(operationString: string, fragmentDefinitions?: Map<string, FragmentDefinitionNode> | null): FragmentDefinitionNode[]

Const getFragmentDependenciesForAST

  • getFragmentDependenciesForAST(parsedOperation: DocumentNode, fragmentDefinitions: Map<string, FragmentDefinitionNode>): FragmentDefinitionNode[]

getHoverInformation

getOperationASTFacts

  • getOperationASTFacts(documentAST: DocumentNode, schema?: GraphQLSchema | null): OperationASTFacts
  • extract all operation nodes, and if schema is present, variable definitions, in a map

    example
     const { variablesToType, operations } = getOperationASTFacts(
       parse('documentString'),
     );
     operations.forEach(op => {
       console.log(op.name, op.operation, op.loc);
     });
      Object.entries(variablesToType).forEach(([variableName, type]) => {
       console.log(variableName, type);
     });

    Parameters

    • documentAST: DocumentNode

      a graphql-js compatible AST node

    • Optional schema: GraphQLSchema | null

      optional schema

    Returns OperationASTFacts

getOperationFacts

  • getOperationFacts(schema?: GraphQLSchema | null, documentString?: string | null): OperationFacts | undefined
  • Provided previous "queryFacts", a GraphQL schema, and a query document string, return a set of facts about that query useful for GraphiQL features.

    If the query cannot be parsed, returns undefined.

    Parameters

    • Optional schema: GraphQLSchema | null

      (optional)

    • Optional documentString: string | null

      the document you want to parse for operations (optional)

    Returns OperationFacts | undefined

getOutline

  • getOutline(documentText: string): Outline | null

getRange

  • getRange(location: SourceLocation, queryText: string): IRange

getTokenAtPosition

getTypeInfo

getVariableCompletions

getVariablesJSONSchema

  • Generates a JSONSchema6 valid document for operation(s) from a map of Map<string, GraphQLInputType>.

    It generates referenced Definitions for each type, so that no graphql types are repeated.

    Note: you must install @types/json-schema if you want a valid result type

    example

    simple usage:

    import { parse } from 'graphql'
    import { collectVariables, getVariablesJSONSchema } from 'graphql-language-service'
    const variablesToType = collectVariables(parse(query), schema)
    const JSONSchema6Result = getVariablesJSONSchema(variablesToType, schema)
    example

    advanced usage:

    
    import { parse } from 'graphql'
    import { collectVariables, getVariablesJSONSchema } from 'graphql-language-service'
    const variablesToType = collectVariables(parse(query), schema)
    
    // you can append `markdownDescription` to JSON schema, which  monaco-json uses.
    const JSONSchema6Result = getVariablesJSONSchema(variablesToType, schema, { useMarkdownDescription: true })
    
    // let's say we want to use it with an IDE extension that expects a JSON file
    // the resultant object literal can be written to string
    import fs from 'fs/promises'
    await fs.writeFile('operation-schema.json', JSON.stringify(JSONSchema6Result, null, 2))

    Parameters

    Returns JSONSchema6

    '

hintList

Const isIgnored

  • isIgnored(ch: string): boolean

list

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

locToRange

  • locToRange(text: string, loc: Location): Range

objectValues

  • objectValues<T>(object: Record<string, T>): Array<T>

offsetToPosition

  • offsetToPosition(text: string, loc: number): Position

onlineParser

opt

p

  • p(value: string, style?: undefined | string): Rule

pointToOffset

  • pointToOffset(text: string, point: TPosition): number

runOnlineParser

  • runOnlineParser(queryText: string, callback: callbackFnType): ContextToken

t

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

validateQuery

  • validateQuery(ast: DocumentNode, schema?: GraphQLSchema | null | undefined, customRules?: Array<ValidationRule> | null, isRelayCompatMode?: undefined | false | true): Array<Diagnostic>

validateWithCustomRules

  • validateWithCustomRules(schema: GraphQLSchema, ast: DocumentNode, customRules?: Array<ValidationRule> | null, isRelayCompatMode?: undefined | false | true, isSchemaDocument?: undefined | false | true): Array<GraphQLError>
  • Validate a GraphQL Document optionally with custom validation rules.

    Parameters

    • schema: GraphQLSchema
    • ast: DocumentNode
    • Optional customRules: Array<ValidationRule> | null
    • Optional isRelayCompatMode: undefined | false | true
    • Optional isSchemaDocument: undefined | false | true

    Returns Array<GraphQLError>

yellow

  • yellow(str: string): string

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"

EXTENSION_DEFINITION

EXTENSION_DEFINITION: "ExtensionDefinition" = "ExtensionDefinition"

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 DIAGNOSTIC_SEVERITY

DIAGNOSTIC_SEVERITY: object

[SEVERITY.Error]

[SEVERITY.Error]: DiagnosticSeverity = 1 as DiagnosticSeverity

[SEVERITY.Hint]

[SEVERITY.Hint]: DiagnosticSeverity = 4 as DiagnosticSeverity

[SEVERITY.Information]

[SEVERITY.Information]: DiagnosticSeverity = 3 as DiagnosticSeverity

[SEVERITY.Warning]

[SEVERITY.Warning]: DiagnosticSeverity = 2 as DiagnosticSeverity

Const FileChangeTypeKind

FileChangeTypeKind: object

Changed

Changed: number = 2

Created

Created: number = 1

Deleted

Deleted: number = 3

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: (string | Rule)[] = [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: (string | Rule)[] = [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'), 'ExtensionDefinition']

Field

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

FieldDef

FieldDef: (string | Rule)[] = [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: (string | Rule)[] = [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: (string | Rule)[] = [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: (string | Rule)[] = [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: (string | Rule)[] = ['NamedType', opt(p('!'))]

NullValue

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

NumberValue

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

ObjectField

ObjectField: (string | Rule)[] = [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; update: any }[] = [{style: 'string',match: (token: Token) => token.kind === 'String',update(state: State, token: Token) {if (token.value.startsWith('"""')) {state.inBlockstring = !token.value.slice(3).endsWith('"""');}},},]

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: (string | Rule)[] = ['Variable', p(':'), 'Type', opt('DefaultValue')]

VariableDefinitions

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

[Kind.ENUM_TYPE_EXTENSION]

[Kind.ENUM_TYPE_EXTENSION]: string[] = ['EnumDef']

[Kind.INPUT_OBJECT_TYPE_EXTENSION]

[Kind.INPUT_OBJECT_TYPE_EXTENSION]: string[] = ['InputDef']

[Kind.INTERFACE_TYPE_EXTENSION]

[Kind.INTERFACE_TYPE_EXTENSION]: string[] = ['InterfaceDef']

[Kind.OBJECT_TYPE_EXTENSION]

[Kind.OBJECT_TYPE_EXTENSION]: string[] = ['ObjectTypeDef']

[Kind.SCALAR_TYPE_EXTENSION]

[Kind.SCALAR_TYPE_EXTENSION]: string[] = ['ScalarDef']

[Kind.SCHEMA_EXTENSION]

[Kind.SCHEMA_EXTENSION]: string[] = ['SchemaDef']

[Kind.UNION_TYPE_EXTENSION]

[Kind.UNION_TYPE_EXTENSION]: string[] = ['UnionDef']

Definition

ExtensionDefinition

Selection

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

Type

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

Value

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

Const RuleKinds

RuleKinds: object

Const SuggestionCommand

SuggestionCommand: object

command

command: string = "editor.action.triggerSuggest"

title

title: string = "Suggestions"

Const defaultJSONSchemaOptions

defaultJSONSchemaOptions: object

useMarkdownDescription

useMarkdownDescription: boolean = false

Generated using TypeDoc