mirror of
https://github.com/graphql-python/graphene.git
synced 2025-02-08 23:50:38 +03:00
Add new mutations argument to schema
This commit is contained in:
parent
bf034ca85f
commit
0a5c8c1268
|
@ -42,7 +42,7 @@ from .enum import Enum
|
||||||
from .field import Field
|
from .field import Field
|
||||||
from .inputobjecttype import InputObjectType
|
from .inputobjecttype import InputObjectType
|
||||||
from .interface import Interface
|
from .interface import Interface
|
||||||
from .objecttype import ObjectType
|
from .objecttype import ObjectType, ObjectTypeOptions
|
||||||
from .resolver import get_default_resolver
|
from .resolver import get_default_resolver
|
||||||
from .scalars import ID, Boolean, Float, Int, Scalar, String
|
from .scalars import ID, Boolean, Float, Int, Scalar, String
|
||||||
from .structures import List, NonNull
|
from .structures import List, NonNull
|
||||||
|
@ -76,6 +76,17 @@ def is_type_of_from_possible_types(possible_types, root, _info):
|
||||||
return isinstance(root, possible_types)
|
return isinstance(root, possible_types)
|
||||||
|
|
||||||
|
|
||||||
|
def convert_mutation_list_to_mutation_type(mutations):
|
||||||
|
fields = {}
|
||||||
|
for mutation in mutations:
|
||||||
|
assert isinstance(mutation, Field)
|
||||||
|
fields[mutation.name] = mutation
|
||||||
|
|
||||||
|
options = ObjectTypeOptions(ObjectType)
|
||||||
|
options.fields = fields
|
||||||
|
return ObjectType.create_type("Mutation", _meta=options)
|
||||||
|
|
||||||
|
|
||||||
class TypeMap(dict):
|
class TypeMap(dict):
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
|
@ -385,6 +396,7 @@ class Schema:
|
||||||
data in your Schema.
|
data in your Schema.
|
||||||
mutation (Optional[Type[ObjectType]]): Root mutation *ObjectType*. Describes entry point for
|
mutation (Optional[Type[ObjectType]]): Root mutation *ObjectType*. Describes entry point for
|
||||||
fields to *create, update or delete* data in your API.
|
fields to *create, update or delete* data in your API.
|
||||||
|
mutations (Optional[Type[Field]]): List of mutation fields to *create, update or delete* data in your API.
|
||||||
subscription (Optional[Type[ObjectType]]): Root subscription *ObjectType*. Describes entry point
|
subscription (Optional[Type[ObjectType]]): Root subscription *ObjectType*. Describes entry point
|
||||||
for fields to receive continuous updates.
|
for fields to receive continuous updates.
|
||||||
types (Optional[List[Type[ObjectType]]]): List of any types to include in schema that
|
types (Optional[List[Type[ObjectType]]]): List of any types to include in schema that
|
||||||
|
@ -400,16 +412,32 @@ class Schema:
|
||||||
self,
|
self,
|
||||||
query=None,
|
query=None,
|
||||||
mutation=None,
|
mutation=None,
|
||||||
|
mutations=None,
|
||||||
subscription=None,
|
subscription=None,
|
||||||
types=None,
|
types=None,
|
||||||
directives=None,
|
directives=None,
|
||||||
auto_camelcase=True,
|
auto_camelcase=True,
|
||||||
):
|
):
|
||||||
self.query = query
|
self.query = query
|
||||||
self.mutation = mutation
|
|
||||||
|
if mutation is not None and mutations is not None:
|
||||||
|
raise Exception(
|
||||||
|
"Both the `mutation` and `mutations` arguments cannot be set when instantiating the Schema. "
|
||||||
|
"Choose one or the other."
|
||||||
|
)
|
||||||
|
|
||||||
|
if mutations is not None:
|
||||||
|
self.mutation = convert_mutation_list_to_mutation_type(mutations)
|
||||||
|
elif mutation is not None:
|
||||||
|
self.mutation = mutation
|
||||||
|
|
||||||
self.subscription = subscription
|
self.subscription = subscription
|
||||||
type_map = TypeMap(
|
type_map = TypeMap(
|
||||||
query, mutation, subscription, types, auto_camelcase=auto_camelcase
|
self.query,
|
||||||
|
self.mutation,
|
||||||
|
self.subscription,
|
||||||
|
types,
|
||||||
|
auto_camelcase=auto_camelcase,
|
||||||
)
|
)
|
||||||
self.graphql_schema = GraphQLSchema(
|
self.graphql_schema = GraphQLSchema(
|
||||||
type_map.query,
|
type_map.query,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user