8000 Added GraphQL improvements and tests (#1788) · PrismJS/prism@b2298b1 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Commit b2298b1

Browse files
Added GraphQL improvements and tests (#1788)
This makes some improvements to GraphQL and expands the existing tests.
1 parent 3e00bb9 commit b2298b1

8 files changed

+194
-23
lines changed

components/prism-graphql.js

+17-10
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,21 @@ Prism.languages.graphql = {
1111
pattern: /@[a-z_]\w*/i,
1212
alias: 'function'
1313
},
14-
'attr-name': /[a-z_]\w*(?=\s*(?:\([^()]*\))?:)/i,
15-
'keyword': [
16-
{
17-
pattern: /(fragment\s+(?!on)[a-z_]\w*\s+|\.{3}\s*)on\b/,
18-
lookbehind: true
19-
},
20-
/\b(?:query|fragment|mutation)\b/
21-
],
22-
'operator': /!|=|\.{3}/,
23-
'punctuation': /[!(){}\[\]:=,]/
14+
'attr-name': {
15+
pattern: /[a-z_]\w*(?=\s*(?:\((?:[^()"]|"(?:\\.|[^\\"\r\n])*")*\))?:)/i,
16+
greedy: true
17+
},
18+
'class-name': {
19+
pattern: /(\b(?:enum|implements|interface|on|scalar|type|union)\s+)[a-zA-Z_]\w*/,
20+
lookbehind: true
21+
},
22+
'fragment': {
23+
pattern: /(\bfragment\s+|\.{3}\s*(?!on\b))[a-zA-Z_]\w*/,
24+
lookbehind: true,
25+
alias: 'function'
26+
},
27+
'keyword': /\b(?:enum|fragment|implements|input|interface|mutation|on|query|scalar|schema|type|union)\b/,
28+
'operator': /[!=|]|\.{3}/,
29+
'punctuation': /[!(){}\[\]:=,]/,
30+
'constant': /\b(?!ID\b)[A-Z][A-Z_\d]*\b/
2431
};

components/prism-graphql.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/languages/graphql/attr-name_feature.test

+24
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22
zuck: user(id: 4) {
33
name
44
}
5+
foo(bar: Int = 0, baz: String = "("): [Int!]!
56
}
67

78
----------------------------------------------------
89

910
[
1011
["punctuation", "{"],
12+
1113
["attr-name", "zuck"],
1214
["punctuation", ":"],
1315
" user",
@@ -19,6 +21,28 @@
1921
["punctuation", "{"],
2022
"\r\n\t\tname\r\n\t",
2123
["punctuation", "}"],
24+
25+
["attr-name", "foo"],
26+
["punctuation", "("],
27+
["attr-name", "bar"],
28+
["punctuation", ":"],
29+
" Int ",
30+
["operator", "="],
31+
["number", "0"],
32+
["punctuation", ","],
33+
["attr-name", "baz"],
34+
["punctuation", ":"],
35+
" String ",
36+
["operator", "="],
37+
["string", "\"(\""],
38+
["punctuation", ")"],
39+
["punctuation", ":"],
40+
["punctuation", "["],
41+
"Int",
42+
["operator", "!"],
43+
["punctuation", "]"],
44+
["operator", "!"],
45+
2246
["punctuation", "}"]
2347
]
2448

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
interface Foo {}
2+
type Foo {}
3+
type Foo implements Bar {}
4+
enum Foo {}
5+
scalar Foo
6+
union Foo
7+
on Foo {}
8+
9+
----------------------------------------------------
10+
11+
[
12+
["keyword", "interface"],
13+
["class-name", "Foo"],
14+
["punctuation", "{"],
15+
["punctuation", "}"],
16+
17+
["keyword", "type"],
18+
["class-name", "Foo"],
19+
["punctuation", "{"],
20+
["punctuation", "}"],
21+
22+
["keyword", "type"],
23+
["class-name", "Foo"],
24+
["keyword", "implements"],
25+
["class-name", "Bar"],
26+
["punctuation", "{"],
27+
["punctuation", "}"],
28+
29+
["keyword", "enum"],
30+
["class-name", "Foo"],
31+
["punctuation", "{"],
32+
["punctuation", "}"],
33+
34+
["keyword", "scalar"],
35+
["class-name", "Foo"],
36+
37+
["keyword", "union"],
38+
["class-name", "Foo"],
39+
40+
["keyword", "on"],
41+
["class-name", "Foo"],
42+
["punctuation", "{"],
43+
["punctuation", "}"]
44+
]
45+
46+
----------------------------------------------------
47+
48+
Checks for class names.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
enum Color {
2+
RED
3+
GREEN
4+
BLUE
5+
}
6+
7+
{
8+
foo(bar: RED) {
9+
baz
10+
}
11+
}
12+
13+
----------------------------------------------------
14+
15+
[
16+
["keyword", "enum"],
17+
["class-name", "Color"],
18+
["punctuation", "{"],
19+
["constant", "RED"],
20+
["constant", "GREEN"],
21+
["constant", "BLUE"],
22+
["punctuation", "}"],
23+
24+
["punctuation", "{"],
25+
"\n\tfoo",
26+
["punctuation", "("],
27+
["attr-name", "bar"],
28+
["punctuation", ":"],
29+
["constant", "RED"],
30+
["punctuation", ")"],
31+
["punctuation", "{"],
32+
"\n\t\tbaz\n\t",
33+
["punctuation", "}"],
34+
["punctuation", "}"]
35+
]
36+
37+
----------------------------------------------------
38+
39+
Checks for constants.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
...frag
3+
}
4+
5+
fragment frag on FooBar {
6+
foo
7+
bar
8+
}
9+
10+
----------------------------------------------------
11+
12+
[
13+
["punctuation", "{"],
14+
["operator", "..."],
15+
["fragment", "frag"],
16+
["punctuation", "}"],
17+
18+
["keyword", "fragment"],
19+
["fragment", "frag"],
20+
["keyword", "on"],
21+
["class-name", "FooBar"],
22+
["punctuation", "{"],
23+
"\r\n\tfoo\r\n\tbar\r\n",
24+
["punctuation", "}"]
25+
]
26+
27+
----------------------------------------------------
28+
29+
Checks for fragments.

tests/languages/graphql/keyword_feature.test

+21-12
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,31 @@
1-
query
1+
enum
22
fragment
3+
implements
4+
input
5+
interface
36
mutation
4-
fragment foo on Bar
5-
... on Foo
7+
on
8+
query
9+
scalar
10+
schema
11+
type
12+
union
613

714
----------------------------------------------------
815

916
[
10-
["keyword", "query"],
11-
["keyword", "fragment"],
12-
["keyword", "mutation"],
13-
["keyword", "fragment"],
14-
" foo ",
15-
["keyword", "on"],
16-
" Bar\r\n",
17-
["operator", "..."],
17+
["keyword", "enum"],
18+
["class-name", "fragment"],
19+
["keyword", "implements"],
20+
["class-name", "input"],
21+
["keyword", "interface"],
22+
["class-name", "mutation"],
1823
["keyword", "on"],
19-
" Foo"
24+
["class-name", "query"],
25+
["keyword", "scalar"],
26+
["class-name", "schema"],
27+
["keyword", "type"],
28+
["class-name", "union"]
2029
]
2130

2231
----------------------------------------------------
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
= ! |
2+
...
3+
4+
----------------------------------------------------
5+
6+
[
7+
["operator", "="],
8+
["operator", "!"],
9+
["operator", "|"],
10+
["operator", "..."]
11+
]
12+
13+
----------------------------------------------------
14+
15+
Checks for operators.

0 commit comments

Comments
 (0)
0