Graphql-tools: is it possible to use with relay?

Created on 22 Feb 2017  Â·  3Comments  Â·  Source: ardatan/graphql-tools

Hi,
I have not found an example of anyone using relay with graphql-tools, is this possible?
For example, in a relay backend:

var userType = new GraphQL.GraphQLObjectType({
  name: 'User',
  description: 'A person who uses our app',
  isTypeOf: function(obj) { return obj instanceof db.User },

  // We use a closure here because we need to refer to widgetType from above
  fields: function() {
    return {
      id: GraphQLRelay.globalIdField('User'),
      name: {
        type: GraphQL.GraphQLString,
        description: 'The name of the user',
      },
      // Here we set up a paged one-to-many relationship ("Connection")
      widgets: {
        description: 'A user\'s collection of widgets',

        // Relay gives us helper functions to define the Connection and its args
        type: GraphQLRelay.connectionDefinitions({name: 'Widget', nodeType: widgetType}).connectionType,
        args: GraphQLRelay.connectionArgs,

        // You can define a resolving function for any field.
        // It can also return a promise if you need async data fetching
        resolve: function(user, args) {
          // This wraps a Connection object around your data array
          // Use connectionFromPromisedArray if you return a promise instead
          return GraphQLRelay.connectionFromArray(db.getWidgetsByUser(user.id), args)
        },
      },
    }
  },
  interfaces: [nodeDefinitions.nodeInterface],
})

Here there are non standard types like GraphQLRelay.connectionArgs, nodeDefinitions.nodeInterface, GraphQLRelay.globalIdField. How does one go about resolving these?

for GraphQLRelay.globalIdField, maybe i can replace it with String, and resolve it in the resolver?
however with GraphQLRelay.connectionArgs, it seems like it is a separate object?

Has anyone done this before with relay and can tell me if its possible?

thanks

Most helpful comment

@benjaminhon I also ran into this issue so I created a library that makes it easy to create a relay compliant library together with graphql-tools called graphql-relay-tools. If you are still running into this problem then this could be a solution.

All 3 comments

@benjaminhon you can definitely use it with relay, but you have to make sure yourself that the schema follows the relay spec. We didn't implement any special things to help people do that, but it might be a useful addition to this package, or a great complementary package (especially adding connections).

@benjaminhon I also ran into this issue so I created a library that makes it easy to create a relay compliant library together with graphql-tools called graphql-relay-tools. If you are still running into this problem then this could be a solution.

i gave up on relay, and went back to redux. Which was what most advised. I
think relay is still too opinionated at the moment , especially with using
the "id", which most databases will already have taken

On Fri, Jun 30, 2017 at 3:43 AM, Dirk-Jan Rutten notifications@github.com
wrote:

@benjaminhon https://github.com/benjaminhon I also ran into this issue
so I created a library that makes it easy to create a relay compliant
library together with graphql-tools called graphql-relay-tools
https://github.com/excitement-engineer/graphql-relay-tools. If you are
still running into this problem then this could be a solution.

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/apollographql/graphql-tools/issues/284#issuecomment-312082772,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AHzqCBgRLTEdocNkjwJhSgjpftXk9_xsks5sI_5kgaJpZM4MITQa
.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

stubailo picture stubailo  Â·  3Comments

ghost picture ghost  Â·  3Comments

confuser picture confuser  Â·  4Comments

flippidippi picture flippidippi  Â·  3Comments

freiksenet picture freiksenet  Â·  4Comments