Skip to content

Commit

Permalink
Fix JSON scalar being non null
Browse files Browse the repository at this point in the history
  • Loading branch information
wyfo committed Jan 7, 2022
1 parent 2454c3c commit 87b141f
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions apischema/graphql/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
to_camel_case,
)

JsonScalar = graphql.GraphQLScalarType("JSON")
JSON_SCALAR = graphql.GraphQLScalarType("JSON")
GRAPHQL_PRIMITIVE_TYPES = {
int: graphql.GraphQLInt,
float: graphql.GraphQLFloat,
Expand Down Expand Up @@ -225,7 +225,8 @@ def name_cache(
name: Optional[str], description: Optional[str]
) -> graphql.GraphQLNonNull:
if name is None:
return graphql.GraphQLNonNull(factory.factory(name, description)) # type: ignore
tp = factory.factory(name, description) # type: ignore
return graphql.GraphQLNonNull(tp) if tp is not JSON_SCALAR else tp
# Method is in cache key because scalar types will have the same method,
# and then be shared by both visitors, while input/output types will have
# their own cache entry.
Expand Down Expand Up @@ -302,7 +303,7 @@ def factory(
name: Optional[str], description: Optional[str]
) -> graphql.GraphQLScalarType:
if name is None:
return JsonScalar
return JSON_SCALAR
else:
return graphql.GraphQLScalarType(name, description=description)

Expand Down Expand Up @@ -362,7 +363,7 @@ def factory(
if name is not None:
return graphql.GraphQLScalarType(name, description=description)
else:
return JsonScalar
return JSON_SCALAR

return TypeFactory(factory)

Expand Down

0 comments on commit 87b141f

Please sign in to comment.