0

I am trying to create a pagination in relay & graphql in my schema. This is my code:

const GraphQLFriendByUser = new GraphQLObjectType({
  name: 'FriendByUser',
  fields: {
    id: globalIdField('FriendByUser'),
    _id: {
      type: GraphQLString,
      resolve: (root) => root._id,
    },
    email: {
      type: GraphQLBoolean,
      resolve: (root) => root.email,
    },
    fullName: {
      type: GraphQLString,
      resolve: (root) => {
        return root.fullName;
      },
    },
  },
  interfaces: [nodeInterface],
});

const {
  connectionType: FriendsByUserConnection,
  edgeType: GraphQLFriendByUserEdge,
} = connectionDefinitions({
  name: 'FriendByUser',
  nodeType: GraphQLFriendByUser,
});

I created this similarly looking at sample in todo-modern, In my TodoListHome component, this is my graphql query:

friendsByUserContext( first: 200 ) @connection(key: "TodoListHome_friendsByUserContext") {
      id
      _id
      fullName
      email
    }  

there's no problem when I update the schema, but when I try to build, this is my error:

Invariant Violation: RelayParser: Unknown field id on type FriendByUserConnection. Source: document TodoListHome_viewer file: C:\Users\PE60\Desktop\socialnetworking-todoapp\js\components\TodoListHome.js.

The execution doesn't even reach on resolve, so I cannot log. but I believe the error is not from there. Help?

gpbaculio
  • 5,693
  • 13
  • 60
  • 102

1 Answers1

0

Since you're using graphql-js, you probably have graphiql hosted on your /graphql endpoint. That's a good place to debug queries and see the structure of your schema. There you'll see that the connection you're talking about has the field edges which has the field node which has the fields you're looking for.

Gregor Weber
  • 690
  • 9
  • 24