Closed cedrickring closed 3 years ago
Hi, apologies for the 10 days delay on response - I hope you've already managed to resolve this 🙂
So @nestjs/graphql
comes with its own ID
scalar, however this gets overridden by nestjs-relay
so that it complies with the relay specification (the custom ID
scalar can be found here). It doesn't surprise me that the schema builder complained that there were multiple definitions for the ID
scalar.
I would recommend using the @NodeType
decorator when defining your schema types, which will automatically add the id
field with the correct scalar type for you.
Hope that helps
Alright this makes sense... So does relay benefit from using ResolvedGlobalId
s for any type it has? Then it makes sense to use @NodeType
on all schema types (so by replacing ObjecType
with NodeType
). I'm still not able to completely get into the Relay ideology 😄
Thankfully the ID
stuff wasn't a huge problem. But now it really does make sense 👍🏽 .
The ResolvedGlobalId
type is useful for the node
/nodes
root queries, which can be used by Relay for refetching data. Relay will hit the node
query with an ID and expect the server to return the correct type. In the star wars example in the tests, you can see that the node resolver will handle IDs that are of types Ship
and Faction
.
The ResolvedGlobalId
type is useful for interpreting the value of the ID to determine which type the server needs to resolve.
The @NodeType
decorator is just a thin wrapper around the @ObjectType
decorator from @nestjs/graphql
that adds the ID field (which will handle the serialization/deserialization automagically).
Alright thanks for the clarification 😄
Maybe the ID
type replacement stuff should be added to the docs as this was not quite clear to me that the GlobalIdScalar
replaces the existing ID implementation.
First of all, thanks for the great package :)
When I integrated
nestjs-relay
in our existing application, there was an issue, where allID
fields had to be of typeResolvedGlobalId
(as far as I understood). All places where I used a simple@Field(type => ID)
with e.g. a string type (though I think it doesn't matter), the schema builder complained about the ID type being defined multiple times with different types. However with onlyResolvedGlobalId
-ID
s the schema builder accepts the schema.Is this intended and should all
ID
s be converted toResolvedGlobalId
s or am I missing something...Thanks in advance 😄