How to create graphql input type for DRF serializer?
I am using django rest framework (DRF) serializers, graphene-django
, and I am able to see the CreateThingMutationInput
type defined in graphiql
:
mutation TestCreate($input: CreateThingMutationInput!) {
createProjectThing(input: $input) {
id
errors {
field
messages
}
}
}
However, I am unable to run:
schema = graphene.Schema(query=Query)
result = schema.execute(self.query, variables=variables)
I get:
[GraphQLError('Unknown type "CreateThingMutationInput".',)]
With the following:
class CreateThingMutation(SerializerMutation):
class Meta:
serializer_class = ThingListViewSerializer
class Mutation(graphene.ObjectType):
debug = graphene.Field(DjangoDebug, name="_debug")
create_project_thing = CreateThingMutation.Field()
I've also tried:
class CreateThingMutationInput(graphene.ObjectType):
input = graphene.Field(convert_serializer_to_input_type(ThingListViewSerializer))
As well as trying to define a:
class Input:
input = graphene.Field(convert_serializer_to_input_type(ThingListViewSerializer))
I can also see the type defined from graphql-codegen
in types.d.ts
:
export type CreateThingMutationInput = {
id?: Maybe<Scalars['Int']>,
...
}
related: