Skip to content

Commit 81e6df8

Browse files
authored
Merge pull request #28 from LiUGraphQL/mixing-of-parts-from-the-DB-schema-and-API-schema
resolve issue #27
2 parents dde6948 + 97667da commit 81e6df8

File tree

3 files changed

+18
-38
lines changed

3 files changed

+18
-38
lines changed

graphql-api-generator/generator.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,13 @@ def run(schema: GraphQLSchema, config: dict):
9494
schema = add_enum_filters(schema)
9595
schema = add_scalar_filters(schema)
9696
schema = add_type_filters(schema)
97+
98+
# remove field arguments for edges (should not be in the API schema)
99+
schema = remove_field_arguments_for_types(schema)
100+
97101
if config.get('generation').get('query_type_filter'):
98102
schema = add_object_type_filters(schema)
103+
99104
if config.get('generation').get('query_list_of'):
100105
schema = add_list_of_types(schema)
101106
schema = add_list_queries(schema)
Lines changed: 3 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,5 @@
1-
"""This comment is bound to the next type"""
2-
interface Pet {
3-
"""This comment is bound to the next field"""
4-
name: String!
5-
}
6-
7-
type Toy {
8-
name: String
9-
}
10-
11-
enum Type {
12-
K
13-
A
14-
C
15-
B
16-
}
17-
18-
type Dog implements Pet {
19-
toys: [Toy]
20-
name: String!
21-
race: Race
22-
b: String
23-
d: String
24-
a: String
25-
c: String
26-
}
27-
28-
type Hero {
29-
pets: [Pet]
30-
}
1+
scalar Date
312

32-
enum Race {
33-
DOBBERMAN
34-
Affenpinscher
35-
Afghan_Hound
36-
Afghan_Shepherd
3+
type Person {
4+
marriedTo(since: Date!): Person
375
}
38-
39-
scalar Date

graphql-api-generator/utils/utils.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ def add_type_filters(schema: GraphQLSchema):
411411
return schema
412412

413413

414-
def add_object_type_filters(schema):
414+
def add_object_type_filters(schema: GraphQLSchema):
415415
for _type in schema.type_map.values():
416416
if not is_schema_defined_type(_type):
417417
continue
@@ -426,6 +426,15 @@ def add_object_type_filters(schema):
426426
return schema
427427

428428

429+
def remove_field_arguments_for_types(schema: GraphQLSchema):
430+
for _type in schema.type_map.values():
431+
if not is_schema_defined_type(_type):
432+
continue
433+
for field_name, field in _type.fields.items():
434+
field.args = {}
435+
return schema
436+
437+
429438
def add_enum_filters(schema: GraphQLSchema):
430439
"""
431440
Add filter inputs for enums (Hasura-style).

0 commit comments

Comments
 (0)