Open aryaniyaps opened 4 months ago
Here is a temporary solution for anyone who has the same issue, until this has been resolved:
import strawberry
from strawberry.relay import GlobalID
# temporary hack until strawberry fixes relay ID scalar generation
ID = strawberry.scalar(
strawberry.ID,
serialize=lambda value: str(value),
parse_value=lambda value: GlobalID.from_id(value=value),
)
schema = Schema(
query=query,
mutation=mutation,
scalar_overrides={GlobalID: ID},
)
Thanks for creating an issue for this. There is already a discussion (#3177) and a PR (#3180) for this. Feel free to join the conversation over there as well.
@aryaniyaps your temporary solution doesn't seem to work for me. I'm getting this:
TypeError: Query fields cannot be resolved.
What version of strawberry are you using?
@aryaniyaps your temporary solution doesn't seem to work for me. I'm getting this:
TypeError: Query fields cannot be resolved.
What version of strawberry are you using?
I think the issue is, after creating a scalar like this;
ID = strawberry.scalar(
strawberry.ID,
serialize=lambda value: str(value),
parse_value=lambda value: GlobalID.from_id(value=value),
)
You are using strawberry.ID
in your schema.
You should be using your own ID scalar instead.
I'm on version 0.235.0 btw
Here is a temporary solution for anyone who has the same issue, until this has been resolved:
import strawberry from strawberry.relay import GlobalID # temporary hack until strawberry fixes relay ID scalar generation ID = strawberry.scalar( strawberry.ID, serialize=lambda value: str(value), parse_value=lambda value: GlobalID.from_id(value=value), ) schema = Schema( query=query, mutation=mutation, scalar_overrides={GlobalID: ID}, )
This was helpful, thank you
Request to output the
ID
scalar instead ofGlobalID
, while generating the GraphQL schemaMy understanding is that
GlobalID
was meant to be an internal helper that resolves nodes, but ended up being a custom scalar.Feature Request Type
Description
Currently, while using the relay integration, and working with node types, like the example code below:
We get a schema output like this:
But in the relay specification, which the GlobalID scalar is based on: https://relay.dev/graphql/objectidentification.htm
calls this scalar by the name
ID
, and notGlobalID
.I think that there is no mention of a custom scalar to be returned for object identification.
This leads to a lot of issues while working with client libraries such as relay, where directives expect the return type to be the scalar type of
ID
, and notGlobalID
.An example relay compiler error is shown below:
Output GraphQL schema (After requested change)
It would be nice if we could change the
GlobalID
scalar being generated toID
Upvote & Fund