Search code examples
reactjsgraphqlrelayjsgraphql-js

RelayJS Invariant Violation with integer query parameter


I'm relatively new to Relay, so this may be an easy mistake I've made but I've been looking for some time already and I haven't found any information about the problem I'm having.

This is the error that I get from my application:

Uncaught Error: Invariant Violation: GraphQLFragmentPointer: Value for the argument to story on query Route should be a string, but it was set to 10. Check that the value is a string.

The problem is I actually want it to be 10 and don't want it to be string. Have I configured something incorrectly?

This is my GraphQL Schema:

var queryType = new GraphQLObjectType({
    name: 'Query',
    fields: () => ({
        node: nodeField,
        story: {
            type: storyType,
            args: {
                storyID: {
                    description: 'Story ID',
                    type: GraphQLInt
                }
            },
            resolve: (root, {storyID}) => {
                if (storyID) {
                    return Story.get(storyID)
                } else {
                    return Story.get(10)
                }
            }
        },
    }),
});

This is the relay route I've defined:

export default class extends Relay.Route {
  static queries = {
    story: () => Relay.QL`
      query {
        story(storyID: $storyID)
      }
    `,
  };

  static paramDefinitions = {
    storyID: {
        required: false
    },
  };

  static routeName = 'StoryRoute';
};

And this is how I instantiate it:

let route = new Route({storyID: 10})

Solution

  • Ok, it looks like I've figured it out finally.

    It appears that root fields are severely limited and can currently only have no parameters, a single string parameter or a multiple string parameters, connected straight with IDs of objects fetched.

    Look for more information here: https://github.com/facebook/relay/issues/112 and here: https://github.com/facebook/relay/issues/94