Skip to content

Commit dfb9f88

Browse files
committed
WIP.
1 parent f0c548d commit dfb9f88

File tree

4 files changed

+98
-57
lines changed

4 files changed

+98
-57
lines changed

graphql/language/ast.py

Lines changed: 57 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -951,14 +951,15 @@ def __hash__(self):
951951

952952

953953
class FieldDefinition(Node):
954-
__slots__ = ('loc', 'name', 'arguments', 'type',)
954+
__slots__ = ('loc', 'name', 'arguments', 'type', 'directives',)
955955
_fields = ('name', 'arguments', 'type',)
956956

957-
def __init__(self, name, arguments, type, loc=None):
957+
def __init__(self, name, arguments, type, loc=None, directives=None):
958958
self.loc = loc
959959
self.name = name
960960
self.arguments = arguments
961961
self.type = type
962+
self.directives = directives
962963

963964
def __eq__(self, other):
964965
return (
@@ -967,7 +968,8 @@ def __eq__(self, other):
967968
self.loc == other.loc and
968969
self.name == other.name and
969970
self.arguments == other.arguments and
970-
self.type == other.type
971+
self.type == other.type and
972+
self.directives == other.directives
971973
)
972974
)
973975

@@ -983,22 +985,25 @@ def __copy__(self):
983985
self.name,
984986
self.arguments,
985987
self.type,
986-
self.loc
988+
self.loc,
989+
self.directives,
987990
)
988991

989992
def __hash__(self):
990993
return id(self)
991994

992995

993996
class InputValueDefinition(Node):
994-
__slots__ = ('loc', 'name', 'type', 'default_value',)
997+
__slots__ = ('loc', 'name', 'type', 'default_value', 'directives')
995998
_fields = ('name', 'type', 'default_value',)
996999

997-
def __init__(self, name, type, default_value=None, loc=None):
1000+
def __init__(self, name, type, default_value=None, loc=None,
1001+
directives=None):
9981002
self.loc = loc
9991003
self.name = name
10001004
self.type = type
10011005
self.default_value = default_value
1006+
self.directives = directives
10021007

10031008
def __eq__(self, other):
10041009
return (
@@ -1007,7 +1012,8 @@ def __eq__(self, other):
10071012
self.loc == other.loc and
10081013
self.name == other.name and
10091014
self.type == other.type and
1010-
self.default_value == other.default_value
1015+
self.default_value == other.default_value and
1016+
self.directives == other.directives
10111017
)
10121018
)
10131019

@@ -1023,29 +1029,32 @@ def __copy__(self):
10231029
self.name,
10241030
self.type,
10251031
self.default_value,
1026-
self.loc
1032+
self.loc,
1033+
self.directives,
10271034
)
10281035

10291036
def __hash__(self):
10301037
return id(self)
10311038

10321039

10331040
class InterfaceTypeDefinition(TypeDefinition):
1034-
__slots__ = ('loc', 'name', 'fields',)
1041+
__slots__ = ('loc', 'name', 'fields', 'directives',)
10351042
_fields = ('name', 'fields',)
10361043

1037-
def __init__(self, name, fields, loc=None):
1044+
def __init__(self, name, fields, loc=None, directives=None):
10381045
self.loc = loc
10391046
self.name = name
10401047
self.fields = fields
1048+
self.directives = directives
10411049

10421050
def __eq__(self, other):
10431051
return (
10441052
self is other or (
10451053
isinstance(other, InterfaceTypeDefinition) and
10461054
self.loc == other.loc and
10471055
self.name == other.name and
1048-
self.fields == other.fields
1056+
self.fields == other.fields and
1057+
self.directives == other.directives
10491058
)
10501059
)
10511060

@@ -1059,29 +1068,32 @@ def __copy__(self):
10591068
return type(self)(
10601069
self.name,
10611070
self.fields,
1062-
self.loc
1071+
self.loc,
1072+
self.directives,
10631073
)
10641074

10651075
def __hash__(self):
10661076
return id(self)
10671077

10681078

10691079
class UnionTypeDefinition(TypeDefinition):
1070-
__slots__ = ('loc', 'name', 'types',)
1080+
__slots__ = ('loc', 'name', 'types', 'directives',)
10711081
_fields = ('name', 'types',)
10721082

1073-
def __init__(self, name, types, loc=None):
1083+
def __init__(self, name, types, loc=None, directives=None):
10741084
self.loc = loc
10751085
self.name = name
10761086
self.types = types
1087+
self.directives = directives
10771088

10781089
def __eq__(self, other):
10791090
return (
10801091
self is other or (
10811092
isinstance(other, UnionTypeDefinition) and
10821093
self.loc == other.loc and
10831094
self.name == other.name and
1084-
self.types == other.types
1095+
self.types == other.types and
1096+
self.directives == other.directives
10851097
)
10861098
)
10871099

@@ -1095,27 +1107,30 @@ def __copy__(self):
10951107
return type(self)(
10961108
self.name,
10971109
self.types,
1098-
self.loc
1110+
self.loc,
1111+
self.directives,
10991112
)
11001113

11011114
def __hash__(self):
11021115
return id(self)
11031116

11041117

11051118
class ScalarTypeDefinition(TypeDefinition):
1106-
__slots__ = ('loc', 'name',)
1119+
__slots__ = ('loc', 'name', 'directives',)
11071120
_fields = ('name',)
11081121

1109-
def __init__(self, name, loc=None):
1122+
def __init__(self, name, loc=None, directives=None):
11101123
self.loc = loc
11111124
self.name = name
1125+
self.directives = directives
11121126

11131127
def __eq__(self, other):
11141128
return (
11151129
self is other or (
11161130
isinstance(other, ScalarTypeDefinition) and
11171131
self.loc == other.loc and
1118-
self.name == other.name
1132+
self.name == other.name and
1133+
self.directives == other.directives
11191134
)
11201135
)
11211136

@@ -1127,29 +1142,32 @@ def __repr__(self):
11271142
def __copy__(self):
11281143
return type(self)(
11291144
self.name,
1130-
self.loc
1145+
self.loc,
1146+
self.directives
11311147
)
11321148

11331149
def __hash__(self):
11341150
return id(self)
11351151

11361152

11371153
class EnumTypeDefinition(TypeDefinition):
1138-
__slots__ = ('loc', 'name', 'values',)
1154+
__slots__ = ('loc', 'name', 'values', 'directives',)
11391155
_fields = ('name', 'values',)
11401156

1141-
def __init__(self, name, values, loc=None):
1157+
def __init__(self, name, values, loc=None, directives=None):
11421158
self.loc = loc
11431159
self.name = name
11441160
self.values = values
1161+
self.directives = directives
11451162

11461163
def __eq__(self, other):
11471164
return (
11481165
self is other or (
11491166
isinstance(other, EnumTypeDefinition) and
11501167
self.loc == other.loc and
11511168
self.name == other.name and
1152-
self.values == other.values
1169+
self.values == other.values and
1170+
self.directives == other.directives
11531171
)
11541172
)
11551173

@@ -1163,27 +1181,30 @@ def __copy__(self):
11631181
return type(self)(
11641182
self.name,
11651183
self.values,
1166-
self.loc
1184+
self.loc,
1185+
self.directives,
11671186
)
11681187

11691188
def __hash__(self):
11701189
return id(self)
11711190

11721191

11731192
class EnumValueDefinition(Node):
1174-
__slots__ = ('loc', 'name',)
1193+
__slots__ = ('loc', 'name', 'directives',)
11751194
_fields = ('name',)
11761195

1177-
def __init__(self, name, loc=None):
1196+
def __init__(self, name, loc=None, directives=None):
11781197
self.loc = loc
11791198
self.name = name
1199+
self.directives = directives
11801200

11811201
def __eq__(self, other):
11821202
return (
11831203
self is other or (
11841204
isinstance(other, EnumValueDefinition) and
11851205
self.loc == other.loc and
1186-
self.name == other.name
1206+
self.name == other.name and
1207+
self.directives == other.directives
11871208
)
11881209
)
11891210

@@ -1195,29 +1216,32 @@ def __repr__(self):
11951216
def __copy__(self):
11961217
return type(self)(
11971218
self.name,
1198-
self.loc
1219+
self.loc,
1220+
self.directives,
11991221
)
12001222

12011223
def __hash__(self):
12021224
return id(self)
12031225

12041226

12051227
class InputObjectTypeDefinition(TypeDefinition):
1206-
__slots__ = ('loc', 'name', 'fields',)
1228+
__slots__ = ('loc', 'name', 'fields', 'directives',)
12071229
_fields = ('name', 'fields',)
12081230

1209-
def __init__(self, name, fields, loc=None):
1231+
def __init__(self, name, fields, loc=None, directives=None):
12101232
self.loc = loc
12111233
self.name = name
12121234
self.fields = fields
1235+
self.directives = directives
12131236

12141237
def __eq__(self, other):
12151238
return (
12161239
self is other or (
12171240
isinstance(other, InputObjectTypeDefinition) and
12181241
self.loc == other.loc and
12191242
self.name == other.name and
1220-
self.fields == other.fields
1243+
self.fields == other.fields and
1244+
self.directives == other.directives
12211245
)
12221246
)
12231247

@@ -1231,7 +1255,8 @@ def __copy__(self):
12311255
return type(self)(
12321256
self.name,
12331257
self.fields,
1234-
self.loc
1258+
self.loc,
1259+
self.directives,
12351260
)
12361261

12371262
def __hash__(self):

graphql/language/parser.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,8 @@ def parse_scalar_type_definition(parser):
603603

604604
return ast.ScalarTypeDefinition(
605605
name=parse_name(parser),
606-
loc=loc(parser, start)
606+
loc=loc(parser, start),
607+
directives=parse_directives(parser),
607608
)
608609

609610

@@ -619,7 +620,8 @@ def parse_object_type_definition(parser):
619620
parse_field_definition,
620621
TokenKind.BRACE_R
621622
),
622-
loc=loc(parser, start)
623+
loc=loc(parser, start),
624+
directives=parse_directives(parser),
623625
)
624626

625627

@@ -631,7 +633,7 @@ def parse_implements_interfaces(parser):
631633
while True:
632634
types.append(parse_named_type(parser))
633635

634-
if peek(parser, TokenKind.BRACE_L):
636+
if not peek(parser, TokenKind.NAME):
635637
break
636638

637639
return types
@@ -644,7 +646,8 @@ def parse_field_definition(parser):
644646
name=parse_name(parser),
645647
arguments=parse_argument_defs(parser),
646648
type=expect(parser, TokenKind.COLON) and parse_type(parser),
647-
loc=loc(parser, start)
649+
loc=loc(parser, start),
650+
directives=parse_directives(parser),
648651
)
649652

650653

@@ -662,7 +665,8 @@ def parse_input_value_def(parser):
662665
name=parse_name(parser),
663666
type=expect(parser, TokenKind.COLON) and parse_type(parser),
664667
default_value=parse_const_value(parser) if skip(parser, TokenKind.EQUALS) else None,
665-
loc=loc(parser, start)
668+
loc=loc(parser, start),
669+
directives=parse_directives(parser),
666670
)
667671

668672

@@ -673,7 +677,8 @@ def parse_interface_type_definition(parser):
673677
return ast.InterfaceTypeDefinition(
674678
name=parse_name(parser),
675679
fields=any(parser, TokenKind.BRACE_L, parse_field_definition, TokenKind.BRACE_R),
676-
loc=loc(parser, start)
680+
loc=loc(parser, start),
681+
directives=parse_directives(parser),
677682
)
678683

679684

@@ -684,7 +689,8 @@ def parse_union_type_definition(parser):
684689
return ast.UnionTypeDefinition(
685690
name=parse_name(parser),
686691
types=expect(parser, TokenKind.EQUALS) and parse_union_members(parser),
687-
loc=loc(parser, start)
692+
loc=loc(parser, start),
693+
directives=parse_directives(parser),
688694
)
689695

690696

@@ -707,7 +713,8 @@ def parse_enum_type_definition(parser):
707713
return ast.EnumTypeDefinition(
708714
name=parse_name(parser),
709715
values=many(parser, TokenKind.BRACE_L, parse_enum_value_definition, TokenKind.BRACE_R),
710-
loc=loc(parser, start)
716+
loc=loc(parser, start),
717+
directives=parse_directives(parser),
711718
)
712719

713720

@@ -716,7 +723,8 @@ def parse_enum_value_definition(parser):
716723

717724
return ast.EnumValueDefinition(
718725
name=parse_name(parser),
719-
loc=loc(parser, start)
726+
loc=loc(parser, start),
727+
directives=parse_directives(parser),
720728
)
721729

722730

@@ -727,7 +735,8 @@ def parse_input_object_type_definition(parser):
727735
return ast.InputObjectTypeDefinition(
728736
name=parse_name(parser),
729737
fields=any(parser, TokenKind.BRACE_L, parse_input_value_def, TokenKind.BRACE_R),
730-
loc=loc(parser, start)
738+
loc=loc(parser, start),
739+
directives=parse_directives(parser),
731740
)
732741

733742

0 commit comments

Comments
 (0)