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

Any example for Relay Node inheritance and Connections? #15

Open
Vani-gurnani opened this issue Mar 16, 2016 · 2 comments
Open

Any example for Relay Node inheritance and Connections? #15

Vani-gurnani opened this issue Mar 16, 2016 · 2 comments

Comments

@Vani-gurnani
Copy link

This is a great library, was wondering if there is implement types from Node which is required for graphql-relay and the connections.

var userType = new GraphQLObjectType({
name: 'User',
description: 'A person who uses our app',
fields: () => ({
id: globalIdField('User'),
firstName: {
type: GraphQLString,
description: "First Name of user"
},
lastName: {
type: GraphQLString,
description: "Last Name of user"
}
}),
interfaces: [nodeInterface],
});

//How to specify interfaces:[nodeInterface] ?

@matthewmueller
Copy link
Owner

Personally i haven't used Relay, so I'm not really sure. Maybe some other folks know better though

@tgriesser
Copy link
Contributor

@Vani-gurnani interfaces are determined by just writing them in the graphql type definitions, and then adding a resolveType on the interface definition object:

interface Node {
  id: ID!
}

type User implements Node {
  id: ID!
  firstName: String,
  lastName: String
}

type Query {
  node(id: ID!): Node
}
{
  Query: {
    node(root, args) { 
      // put resolver here 
    }
  },
  User: {
    id: globalIdField('User')
  },
  Node: {
    resolveType(value) {
      if (isUser(value)) {
        return 'User'
      }
    }
  }
}

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

3 participants