Hello
I started out with the relay-starter-kit
and also worked my way through the Relay and GraphQL documentation. But there are quite a few areas that are unexplained and mysterious.
Seriously I read a lot of documentations everywhere about all these things but couldn't find any satisfying explanations for the following questions:
What is this for? I put logging but it never even gets 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],
Maybe related to that, what does the node
field here do:
var queryType = new GraphQLObjectType({
name: 'Query',
fields: () => ({
node: nodeField,
// Add your own root fields here
viewer: {
type: userType,
resolve: () => getViewer(),
},
}),
});
And what is the magic around the id
field? What is globalIdField
for?
I have an id
in my database and thought I could use it in my GraphQL objects:
Instead of:
id: globalIdField('User'),
I want to use my database id:
id: {
type: GraphQLID,
description: 'The identifier'
},
But if I do that I get an error in the browser saying RelayQueryWriter: Could not find a type name for record '1'
.
I can get rid of that error by adding __typename
to my component containers Relay Query but that seems all wrong.
It would be great if you could give some deeper insides and a better explanation here and enhance the official documentation.
I asked the same on Stack Overflow
Thank you