Skip to content

Commit

Permalink
Backport SDL syntax for multiple interfaces…
Browse files Browse the repository at this point in the history
Equivalent to graphql/graphql-js#1169
(excluding the 'allowLegacySDLImplementsInterface' option)
  • Loading branch information
cpmsmith committed Apr 18, 2022
1 parent 6e2fbcc commit 016d975
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 10 deletions.
3 changes: 3 additions & 0 deletions graphql/language/lexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class TokenKind(object):
INT = 17
FLOAT = 18
STRING = 19
AMP = 20


def get_token_desc(token):
Expand Down Expand Up @@ -111,6 +112,7 @@ def get_token_kind_desc(kind):
TokenKind.INT: "Int",
TokenKind.FLOAT: "Float",
TokenKind.STRING: "String",
TokenKind.AMP: "&",
}


Expand All @@ -135,6 +137,7 @@ def char_code_at(s, pos):
ord("{"): TokenKind.BRACE_L,
ord("|"): TokenKind.PIPE,
ord("}"): TokenKind.BRACE_R,
ord("&"): TokenKind.AMP,
}


Expand Down
2 changes: 1 addition & 1 deletion graphql/language/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,7 @@ def parse_implements_interfaces(parser):
while True:
types.append(parse_named_type(parser))

if not peek(parser, TokenKind.NAME):
if not skip(parser, TokenKind.AMP):
break

return types
Expand Down
2 changes: 1 addition & 1 deletion graphql/language/printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def leave_ObjectTypeDefinition(self, node, *args):
[
"type",
node.name,
wrap("implements ", join(node.interfaces, ", ")),
wrap("implements ", join(node.interfaces, " & ")),
join(node.directives, " "),
block(node.fields),
],
Expand Down
8 changes: 4 additions & 4 deletions graphql/language/tests/test_schema_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def test_parses_simple_type_inheriting_interface():

def test_parses_simple_type_inheriting_multiple_interfaces():
# type: () -> None
body = "type Hello implements Wo, rld { }"
body = "type Hello implements Wo & rld { }"
loc = create_loc_fn(body)
doc = parse(body)
expected = ast.Document(
Expand All @@ -165,15 +165,15 @@ def test_parses_simple_type_inheriting_multiple_interfaces():
name=ast.Name(value="Wo", loc=loc(22, 24)), loc=loc(22, 24)
),
ast.NamedType(
name=ast.Name(value="rld", loc=loc(26, 29)), loc=loc(26, 29)
name=ast.Name(value="rld", loc=loc(27, 30)), loc=loc(27, 30)
),
],
directives=[],
fields=[],
loc=loc(0, 33),
loc=loc(0, 34),
)
],
loc=loc(0, 33),
loc=loc(0, 34),
)
assert doc == expected

Expand Down
2 changes: 1 addition & 1 deletion graphql/utils/schema_printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def _print_object(type):
# type: (GraphQLObjectType) -> str
interfaces = type.interfaces
implemented_interfaces = (
" implements {}".format(", ".join(i.name for i in interfaces))
" implements {}".format(" & ".join(i.name for i in interfaces))
if interfaces
else ""
)
Expand Down
4 changes: 2 additions & 2 deletions graphql/utils/tests/test_extend_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ def test_extends_objects_by_adding_implemented_new_interfaces():
fizz: String
}
type Foo implements SomeInterface, NewInterface {
type Foo implements SomeInterface & NewInterface {
name: String
some: SomeInterface
tree: [Foo]!
Expand Down Expand Up @@ -637,7 +637,7 @@ def test_extends_objects_multiple_times():
foo: Foo
}
type Biz implements NewInterface, SomeInterface {
type Biz implements NewInterface & SomeInterface {
fizz: String
buzz: String
name: String
Expand Down
2 changes: 1 addition & 1 deletion graphql/utils/tests/test_schema_printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ def test_prints_multiple_interfaces():
int: Int
}
type Bar implements Foo, Baaz {
type Bar implements Foo & Baaz {
str: String
int: Int
}
Expand Down

0 comments on commit 016d975

Please sign in to comment.