Skip to content

Multiple Mutaion classes in schema #333

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mzohaibqc opened this issue Oct 21, 2016 · 3 comments
Closed

Multiple Mutaion classes in schema #333

mzohaibqc opened this issue Oct 21, 2016 · 3 comments

Comments

@mzohaibqc
Copy link

mzohaibqc commented Oct 21, 2016

I have multilpe services and each have lot of mutations like

class SnMutations(graphene.ObjectType):
    # Event mutations
    create_event = CreateEvent.Field()
    update_event = UpdateEvent.Field()
    delete_event = DeleteEvent.Field()

    # Venue mutations, Meetup does not allow to update a venue. Also it does not make sense.
    create_venue = CreateVenue.Field()

    # EventOrganizer mutations
    create_event_organizer = CreateEventOrganizer.Field()
    update_event_organizer = UpdateEventOrganizer.Field()
    delete_event_organizer = DeleteEventOrganizer.Field()

    # Authorization mutations
    refresh_token = RefreshToken.Field()
    add_social_network_credentials = AddSocialNetworkCredentials.Field()

and

class CandidateMutation(graphene.ObjectType):
    create_candidate = CreateCandidate.Field()
    update_candidate = UpdateCandidate.Field()

and more

Now I want to create schema with all these mutations but I want to send query for each mutation under a specific key like sn_mutations and candidate_mutations for candidate service.

mutation {
    sn_mutations {
         create_event (some values) {

        }
    }
}

But I can only pass a single class in schema.

schema = Schema(query=Query, mutation=SnMutation, auto_camelcase=False)

I tries graphene.AbstractType and Inherited main Mutation class from all other Mutation class but in this way I can not divide mutation for every service in query under a specific key like sn_mutations and candidate_mutations.
Any help is most appreciated.

@ekampf
Copy link
Contributor

ekampf commented Oct 24, 2016

Hey @mzohaibqc
Just note that while using hierarchies in mutations is valid under the GraphQL spec, it will not work if you use Relay on your client to call it.
Relay enforces all mutations to be top-level: facebook/relay#551

Its very annoying, but thats the way it is :(

Anyway, if you still want to do it all you need to do is define a root:

class MutationRoot(graphene.ObjectType):
   sn_mutations = graphene.Field(SnMutations)

   def resolve_sn_mutations(self, *_):
       return SnMutations()

@syrusakbary
Copy link
Member

As Eran pointed, all mutations are enforced to be top level.

Related spec improvement in the GraphQL spec: graphql/graphql-spec#252

@jkimbo
Copy link
Member

jkimbo commented Feb 18, 2018

Hi @mzohaibqc . We're currently going through old issues that appear to have gone stale (ie. not updated in about the last 6 months) to try and clean up the issue tracker. If this is still important to you please comment and we'll re-open this.

Thanks!

@jkimbo jkimbo closed this as completed Feb 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants