I started with relay-starter-kit , and also worked my way through the Relay and GraphQL documentation. But there are many areas that are inexplicable and mysterious.
Seriously, I read a lot of documents around the world about all these things, but I could not find satisfactory explanations on the following issues:
What is this for? I put the log, but it is not even called at all:
var {nodeInterface, nodeField} = nodeDefinitions( (globalId) => { var {type, id} = fromGlobalId(globalId); if (type === 'User') { return getUser(id); } else if (type === 'Widget') { return getWidget(id); } else { return null; } }, (obj) => { if (obj instanceof User) { return userType; } else if (obj instanceof Widget) { return widgetType; } else { return null; } } );
And what is the actual effect of this:
interfaces: [nodeInterface],
Perhaps this is due to what the node field does here:
var queryType = new GraphQLObjectType({ name: 'Query', fields: () => ({ node: nodeField,
And what is the magic around the id field? What is globalIdField for?
I have an id in my database and I thought I could use it in my GraphQL objects:
Instead:
id: globalIdField('User'),
I want to use my database id:
id: { type: GraphQLID, description: 'The identifier' },
But if I do, I get an error in the browser saying RelayQueryWriter: Could not find a type name for record '1' .
I can get rid of this error by adding __typename to my Relay Query component containers, but this seems to be wrong.
It would be great if you could give deeper insides and a better explanation here and improve the official documentation.
thank