Skip to content

Commit

Permalink
Allow list types in RootSchemaQuery (#284)
Browse files Browse the repository at this point in the history
* Allow list types in RootSchemaQuery

* Use list types in schema generation
  • Loading branch information
bojanserafimov committed May 21, 2019
1 parent 819a709 commit 81b588d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
4 changes: 4 additions & 0 deletions graphql_compiler/compiler/compiler_frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,10 @@ def _compile_root_ast_to_ir(schema, ast, type_equivalence_hints=None):
# Validation passed, so the base_start_type must exist as a field of the root query.
current_schema_type = get_field_type_from_schema(schema.get_query_type(), base_start_type)

# Allow list types at the query root in the schema.
if isinstance(current_schema_type, GraphQLList):
current_schema_type = current_schema_type.of_type

# Construct the start location of the query and its associated metadata.
location = Location((base_start_type,))
base_location_info = LocationInfo(
Expand Down
2 changes: 1 addition & 1 deletion graphql_compiler/schema_generation/graphql_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ def get_graphql_schema_from_schema_graph(schema_graph, class_to_field_type_overr
# Create the root query GraphQL type. Consists of all non-union classes, i.e.
# all non-abstract classes (as GraphQL types) and all abstract classes (as GraphQL interfaces).
RootSchemaQuery = GraphQLObjectType('RootSchemaQuery', OrderedDict([
(name, GraphQLField(value))
(name, GraphQLField(GraphQLList(value)))
for name, value in sorted(six.iteritems(graphql_types), key=lambda x: x[0])
if not isinstance(value, GraphQLUnionType)
]))
Expand Down
20 changes: 10 additions & 10 deletions graphql_compiler/tests/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,16 +157,16 @@
}
type RootSchemaQuery {
Animal: Animal
BirthEvent: BirthEvent
Entity: Entity
Event: Event
FeedingEvent: FeedingEvent
Food: Food
FoodOrSpecies: FoodOrSpecies
Location: Location
Species: Species
UniquelyIdentifiable: UniquelyIdentifiable
Animal: [Animal]
BirthEvent: [BirthEvent]
Entity: [Entity]
Event: [Event]
FeedingEvent: [FeedingEvent]
Food: [Food]
FoodOrSpecies: [FoodOrSpecies]
Location: [Location]
Species: [Species]
UniquelyIdentifiable: [UniquelyIdentifiable]
}
type Species implements Entity, UniquelyIdentifiable {
Expand Down

0 comments on commit 81b588d

Please sign in to comment.