Skip to content
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

Schema, handling many-to-many queries #173

Closed
ghost opened this issue Sep 12, 2015 · 4 comments
Closed

Schema, handling many-to-many queries #173

ghost opened this issue Sep 12, 2015 · 4 comments

Comments

@ghost
Copy link

ghost commented Sep 12, 2015

I have a problem with this specific scenario, and have not found much documentation. How in JS can i make a schema that allows me to query many to many ObjectTypes?

@ghost ghost changed the title Schema, handing many-to-many queries Schema, handling many-to-many queries Sep 12, 2015
@freiksenet
Copy link
Contributor

You can define a GraphQLList on both sides.

const User = new GraphQLObjectType({
   name: 'User', 
   fields: () => ({
     groups: {
       type: new GraphQLList(Group)
     }
  })
});

const Group = new GraphQLObjectType({
   name: 'Group', 
   fields: () => ({
     users: {
       type: new GraphQLList(User)
     }
  })
});

How the resolve function would work is totally up to how you store your data.

@leebyron
Copy link
Contributor

leebyron commented Oct 1, 2015

@freiksenet is dead on - closing this task.

@leebyron leebyron closed this as completed Oct 1, 2015
@LouisStAmour
Copy link

For those who (like me) stumble on this page from Google, instead of a list, consider connections for the pagination benefits: https://facebook.github.io/relay/docs/graphql-connections.html -- see also graphql/graphql-relay-js#20

@YasinYA
Copy link

YasinYA commented Dec 17, 2018

How about making mutations?

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