Skip to content

Commit 016d975

Browse files
committed
Backport SDL syntax for multiple interfaces…
Equivalent to graphql/graphql-js#1169 (excluding the 'allowLegacySDLImplementsInterface' option)
1 parent 6e2fbcc commit 016d975

File tree

7 files changed

+13
-10
lines changed

7 files changed

+13
-10
lines changed

graphql/language/lexer.py

+3
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ class TokenKind(object):
7676
INT = 17
7777
FLOAT = 18
7878
STRING = 19
79+
AMP = 20
7980

8081

8182
def get_token_desc(token):
@@ -111,6 +112,7 @@ def get_token_kind_desc(kind):
111112
TokenKind.INT: "Int",
112113
TokenKind.FLOAT: "Float",
113114
TokenKind.STRING: "String",
115+
TokenKind.AMP: "&",
114116
}
115117

116118

@@ -135,6 +137,7 @@ def char_code_at(s, pos):
135137
ord("{"): TokenKind.BRACE_L,
136138
ord("|"): TokenKind.PIPE,
137139
ord("}"): TokenKind.BRACE_R,
140+
ord("&"): TokenKind.AMP,
138141
}
139142

140143

graphql/language/parser.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,7 @@ def parse_implements_interfaces(parser):
718718
while True:
719719
types.append(parse_named_type(parser))
720720

721-
if not peek(parser, TokenKind.NAME):
721+
if not skip(parser, TokenKind.AMP):
722722
break
723723

724724
return types

graphql/language/printer.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ def leave_ObjectTypeDefinition(self, node, *args):
169169
[
170170
"type",
171171
node.name,
172-
wrap("implements ", join(node.interfaces, ", ")),
172+
wrap("implements ", join(node.interfaces, " & ")),
173173
join(node.directives, " "),
174174
block(node.fields),
175175
],

graphql/language/tests/test_schema_parser.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ def test_parses_simple_type_inheriting_interface():
153153

154154
def test_parses_simple_type_inheriting_multiple_interfaces():
155155
# type: () -> None
156-
body = "type Hello implements Wo, rld { }"
156+
body = "type Hello implements Wo & rld { }"
157157
loc = create_loc_fn(body)
158158
doc = parse(body)
159159
expected = ast.Document(
@@ -165,15 +165,15 @@ def test_parses_simple_type_inheriting_multiple_interfaces():
165165
name=ast.Name(value="Wo", loc=loc(22, 24)), loc=loc(22, 24)
166166
),
167167
ast.NamedType(
168-
name=ast.Name(value="rld", loc=loc(26, 29)), loc=loc(26, 29)
168+
name=ast.Name(value="rld", loc=loc(27, 30)), loc=loc(27, 30)
169169
),
170170
],
171171
directives=[],
172172
fields=[],
173-
loc=loc(0, 33),
173+
loc=loc(0, 34),
174174
)
175175
],
176-
loc=loc(0, 33),
176+
loc=loc(0, 34),
177177
)
178178
assert doc == expected
179179

graphql/utils/schema_printer.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def _print_object(type):
128128
# type: (GraphQLObjectType) -> str
129129
interfaces = type.interfaces
130130
implemented_interfaces = (
131-
" implements {}".format(", ".join(i.name for i in interfaces))
131+
" implements {}".format(" & ".join(i.name for i in interfaces))
132132
if interfaces
133133
else ""
134134
)

graphql/utils/tests/test_extend_schema.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ def test_extends_objects_by_adding_implemented_new_interfaces():
568568
fizz: String
569569
}
570570
571-
type Foo implements SomeInterface, NewInterface {
571+
type Foo implements SomeInterface & NewInterface {
572572
name: String
573573
some: SomeInterface
574574
tree: [Foo]!
@@ -637,7 +637,7 @@ def test_extends_objects_multiple_times():
637637
foo: Foo
638638
}
639639
640-
type Biz implements NewInterface, SomeInterface {
640+
type Biz implements NewInterface & SomeInterface {
641641
fizz: String
642642
buzz: String
643643
name: String

graphql/utils/tests/test_schema_printer.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ def test_prints_multiple_interfaces():
390390
int: Int
391391
}
392392
393-
type Bar implements Foo, Baaz {
393+
type Bar implements Foo & Baaz {
394394
str: String
395395
int: Int
396396
}

0 commit comments

Comments
 (0)