blob: 01d5ca25ffc2923ad005713330b0e07390e254c4 [file] [log] [blame]
Jon Parise4ce1cb52024-12-23 09:57:42 +01001" Vim syntax file
2" Language: graphql
3" Maintainer: Jon Parise <jon@indelible.org>
4" Filenames: *.graphql *.graphqls *.gql
5" URL: https://github.com/jparise/vim-graphql
6" License: MIT <https://opensource.org/license/mit>
7" Last Change: 2024 Dec 21
8
9if !exists('main_syntax')
10 if exists('b:current_syntax')
11 finish
12 endif
13 let main_syntax = 'graphql'
14endif
15
16syn case match
17
18syn match graphqlComment "#.*$" contains=@Spell
19
20syn match graphqlOperator "=" display
21syn match graphqlOperator "!" display
22syn match graphqlOperator "|" display
23syn match graphqlOperator "&" display
24syn match graphqlOperator "\M..." display
25
26syn keyword graphqlBoolean true false
27syn keyword graphqlNull null
28syn match graphqlNumber "-\=\<\%(0\|[1-9]\d*\)\%(\.\d\+\)\=\%([eE][-+]\=\d\+\)\=\>" display
29syn region graphqlString start=+"+ skip=+\\\\\|\\"+ end=+"\|$+
30syn region graphqlString start=+"""+ skip=+\\"""+ end=+"""+
31
32syn keyword graphqlKeyword repeatable nextgroup=graphqlKeyword skipwhite
33syn keyword graphqlKeyword on nextgroup=graphqlType,graphqlDirectiveLocation skipwhite
34
35syn keyword graphqlStructure enum scalar type union nextgroup=graphqlType skipwhite
36syn keyword graphqlStructure input interface subscription nextgroup=graphqlType skipwhite
37syn keyword graphqlStructure implements nextgroup=graphqlType skipwhite
38syn keyword graphqlStructure query mutation fragment nextgroup=graphqlName skipwhite
39syn keyword graphqlStructure directive nextgroup=graphqlDirective skipwhite
40syn keyword graphqlStructure extend nextgroup=graphqlStructure skipwhite
41syn keyword graphqlStructure schema nextgroup=graphqlFold skipwhite
42
43syn match graphqlDirective "\<@\h\w*\>" display
44syn match graphqlVariable "\<\$\h\w*\>" display
45syn match graphqlName "\<\h\w*\>" display
46syn match graphqlType "\<_*\u\w*\>" display
47
48" https://spec.graphql.org/October2021/#ExecutableDirectiveLocation
49syn keyword graphqlDirectiveLocation QUERY MUTATION SUBSCRIPTION FIELD
50syn keyword graphqlDirectiveLocation FRAGMENT_DEFINITION FRAGMENT_SPREAD
51syn keyword graphqlDirectiveLocation INLINE_FRAGMENT VARIABLE_DEFINITION
52" https://spec.graphql.org/October2021/#TypeSystemDirectiveLocation
53syn keyword graphqlDirectiveLocation SCHEMA SCALAR OBJECT FIELD_DEFINITION
54syn keyword graphqlDirectiveLocation ARGUMENT_DEFINITION INTERFACE UNION
55syn keyword graphqlDirectiveLocation ENUM ENUM_VALUE INPUT_OBJECT
56syn keyword graphqlDirectiveLocation INPUT_FIELD_DEFINITION
57
58syn keyword graphqlMetaFields __schema __type __typename
59
60syn region graphqlFold matchgroup=graphqlBraces start="{" end="}" transparent fold contains=ALLBUT,graphqlStructure
61syn region graphqlList matchgroup=graphqlBraces start="\[" end="]" transparent contains=ALLBUT,graphqlDirective,graphqlStructure
62
63if main_syntax ==# 'graphql'
64 syn sync minlines=500
65endif
66
67hi def link graphqlComment Comment
68hi def link graphqlOperator Operator
69
70hi def link graphqlBraces Delimiter
71
72hi def link graphqlBoolean Boolean
73hi def link graphqlNull Keyword
74hi def link graphqlNumber Number
75hi def link graphqlString String
76
77hi def link graphqlDirective PreProc
78hi def link graphqlDirectiveLocation Special
79hi def link graphqlName Identifier
80hi def link graphqlMetaFields Special
81hi def link graphqlKeyword Keyword
82hi def link graphqlStructure Structure
83hi def link graphqlType Type
84hi def link graphqlVariable Identifier
85
86let b:current_syntax = 'graphql'
87
88if main_syntax ==# 'graphql'
89 unlet main_syntax
90endif