Skip to content

Commit

Permalink
Add support for GraphQL (resolves highlightjs#1471)
Browse files Browse the repository at this point in the history
  • Loading branch information
dpeek committed Jun 12, 2017
1 parent 1ee1647 commit b7401ac
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 0 deletions.
1 change: 1 addition & 0 deletions AUTHORS.en.txt
Expand Up @@ -252,3 +252,4 @@ Contributors:
- Nicolas LLOBERA <nllobera@gmail.com>
- Morten Piibeleht <morten.piibeleht@gmail.com>
- Martin Clausen <martin.clausene@gmail.com>
- David Peek <mail@dpeek.com>
1 change: 1 addition & 0 deletions AUTHORS.ru.txt
Expand Up @@ -252,3 +252,4 @@ URL: https://highlightjs.org/
- Николя Ллобера <nllobera@gmail.com>
- Мортен Пибелехт <morten.piibeleht@gmail.com>
- Мартин Клаузен <martin.clausene@gmail.com>
- Давид Пээк <mail@dpeek.com>
6 changes: 6 additions & 0 deletions CHANGES.md
@@ -1,3 +1,9 @@
## Version 9.13.0

New language:

- *GraphQL* graph query language by [David Peek][].

## Version 9.12.0

New language:
Expand Down
41 changes: 41 additions & 0 deletions src/languages/graphql.js
@@ -0,0 +1,41 @@
/*
Language: GraphQL
Author: David Peek <mail@dpeek.com>
Description: GraphQL schema, query, mutation and subscription
*/

function(hljs) {
return {
aliases: ['gql'],
keywords: {
keyword: 'query mutation subscription type interface union scalar fragment enum on ...',
literal: 'true false null'
},
contains: [
hljs.HASH_COMMENT_MODE,
hljs.QUOTE_STRING_MODE,
hljs.NUMBER_MODE,
{ className: 'type',
begin: '[^\\w][A-Z][a-z]', end: '\\W',
excludeEnd: true
},
{ className: 'literal',
begin: '[^\\w][A-Z][A-Z]', end: '\\W',
excludeEnd: true
},
{ className: 'variable',
begin: '\\$', end: '\\W',
excludeEnd: true
},
{
className: 'keyword',
begin: '[.]{2}', end: '\\.',
},
{
className: 'meta',
begin: '@', end: '\\W',
excludeEnd: true
}
]
}
}
63 changes: 63 additions & 0 deletions test/detect/graphql/default.txt
@@ -0,0 +1,63 @@
# Comment

type ComplexType {
name: String!
}

enum EnumType {
MOBILE
DESKTOP
}

union UnionType = ComplexType | EnumType

query queryName($foo: ComplexType, $site: Site = MOBILE) {
whoever123is: node(id: [123, 456]) {
id ,
... on User @defer {
field2 {
id ,
alias: field1(first:10, after:$foo,) @include(if: $foo) {
id,
...frag
}
}
}
... @skip(unless: $foo) {
id
}
... {
id
}
}
}

mutation likeStory {
like(story: 123) @defer {
story {
id
}
}
}

subscription StoryLikeSubscription($input: StoryLikeSubscribeInput) {
storyLikeSubscribe(input: $input) {
story {
likers {
count
}
likeSentence {
text
}
}
}
}

fragment frag on Friend {
foo(size: $size, bar: $b, obj: {key: "value"})
}

{
unnamed(truthy: true, falsey: false, nullish: null),
query
}

0 comments on commit b7401ac

Please sign in to comment.