relay.GlobalID naming issue?

type CreateTodoPayload {
todoEdge: TodoEdge!
}

"""Date with time (isoformat)"""
scalar DateTime

type DeleteTodoPayload {
deletedTodoId: GlobalID
}

"""
The `ID` scalar type represents a unique identifier, often used to refetch an object or as key for a cache. The ID type appears in a JSON response as a String; however, it is not intended to be human-readable. When expected as an input type, any string (such as `"4"`) or integer (such as `4`) input value will be accepted as an ID.
"""
scalar GlobalID @specifiedBy(url: "https://relay.dev/graphql/objectidentification.htm")

type Mutation {
"""Create a new todo."""
createTodo(
"""The content of the todo."""
content: String!
): CreateTodoPayload!

"""Delete a todo by ID."""
deleteTodo(
"""The ID of the todo to delete."""
todoId: GlobalID!
): DeleteTodoPayload!
}

"""An object with a Globally Unique ID"""
interface Node {
"""The Globally Unique ID of this object"""
id: GlobalID!
}

"""Information to aid in pagination."""
type PageInfo {
"""When paginating forwards, are there more items?"""
hasNextPage: Boolean!

"""When paginating backwards, are there more items?"""
hasPreviousPage: Boolean!

"""When paginating backwards, the cursor to continue."""
startCursor: String

"""When paginating forwards, the cursor to continue."""
endCursor: String
}

type Query {
node(
"""The ID of the object."""
id: GlobalID!
): Node!

"""Get all todos available."""
todos(before: String = null, after: String = null, first: Int = null, last: Int = null): TodoConnection!
}
type CreateTodoPayload {
todoEdge: TodoEdge!
}

"""Date with time (isoformat)"""
scalar DateTime

type DeleteTodoPayload {
deletedTodoId: GlobalID
}

"""
The `ID` scalar type represents a unique identifier, often used to refetch an object or as key for a cache. The ID type appears in a JSON response as a String; however, it is not intended to be human-readable. When expected as an input type, any string (such as `"4"`) or integer (such as `4`) input value will be accepted as an ID.
"""
scalar GlobalID @specifiedBy(url: "https://relay.dev/graphql/objectidentification.htm")

type Mutation {
"""Create a new todo."""
createTodo(
"""The content of the todo."""
content: String!
): CreateTodoPayload!

"""Delete a todo by ID."""
deleteTodo(
"""The ID of the todo to delete."""
todoId: GlobalID!
): DeleteTodoPayload!
}

"""An object with a Globally Unique ID"""
interface Node {
"""The Globally Unique ID of this object"""
id: GlobalID!
}

"""Information to aid in pagination."""
type PageInfo {
"""When paginating forwards, are there more items?"""
hasNextPage: Boolean!

"""When paginating backwards, are there more items?"""
hasPreviousPage: Boolean!

"""When paginating backwards, the cursor to continue."""
startCursor: String

"""When paginating forwards, the cursor to continue."""
endCursor: String
}

type Query {
node(
"""The ID of the object."""
id: GlobalID!
): Node!

"""Get all todos available."""
todos(before: String = null, after: String = null, first: Int = null, last: Int = null): TodoConnection!
}
15 Replies
Aryan Iyappan
Aryan IyappanOP5mo ago
type Todo implements Node {
"""The Globally Unique ID of this object"""
id: GlobalID!
content: String!
completed: Boolean!
createdAt: DateTime!
updatedAt: DateTime
}

type TodoConnection {
"""Pagination data for this connection"""
pageInfo: PageInfo!

"""Contains the nodes in this connection"""
edges: [TodoEdge!]!
}

"""An edge in a connection."""
type TodoEdge {
"""A cursor for use in pagination"""
cursor: String!

"""The item at the end of the edge"""
node: Todo!
}
type Todo implements Node {
"""The Globally Unique ID of this object"""
id: GlobalID!
content: String!
completed: Boolean!
createdAt: DateTime!
updatedAt: DateTime
}

type TodoConnection {
"""Pagination data for this connection"""
pageInfo: PageInfo!

"""Contains the nodes in this connection"""
edges: [TodoEdge!]!
}

"""An edge in a connection."""
type TodoEdge {
"""A cursor for use in pagination"""
cursor: String!

"""The item at the end of the edge"""
node: Todo!
}
this is the schema currently being generated while using the strawberry relay integration. However, this outputs all the IDs under a scalar named GlobalID The issue for me is, while using relay on the frontend, the relay compiler expects these fields to be of the scalar named ID exactly, while updating the data after mutations, using directives Here's the error I get from relay:
> relay-compiler

[INFO] [default] compiling...
[ERROR] Error: ✖︎ Invalid use of @deleteEdge on field 'deletedTodoId'. Expected field type 'ID', got 'GlobalID'.

client/src/components/home-page/Todo.tsx:20:21
19 │ deleteTodo(todoId: $todoId) {
20 │ deletedTodoId @deleteEdge(connections: $connections)
│ ^^^^^^^^^^^
21 │ }

[ERROR] Compilation failed.
[ERROR] Unable to run relay compiler. Error details:
Failed to build:
- Validation errors: 1 error(s) encountered above.
> relay-compiler

[INFO] [default] compiling...
[ERROR] Error: ✖︎ Invalid use of @deleteEdge on field 'deletedTodoId'. Expected field type 'ID', got 'GlobalID'.

client/src/components/home-page/Todo.tsx:20:21
19 │ deleteTodo(todoId: $todoId) {
20 │ deletedTodoId @deleteEdge(connections: $connections)
│ ^^^^^^^^^^^
21 │ }

[ERROR] Compilation failed.
[ERROR] Unable to run relay compiler. Error details:
Failed to build:
- Validation errors: 1 error(s) encountered above.
the relay specification calls this scalar as ID only, so why is strawberry outputting this as GlobalID?? cc @contributors
Aryan Iyappan
Aryan IyappanOP5mo ago
GitHub
(Relay) Output ID instead of GlobalID in GraphQL schema · Issue #35...
Request to output the ID scalar instead of GlobalID, while generating the GraphQL schema My understanding is that GlobalID was meant to be an internal helper that resolves nodes, but ended up being...
Unknown User
Unknown User5mo ago
Message Not Public
Sign In & Join Server To View
Aryan Iyappan
Aryan IyappanOP5mo ago
Mm, I think it would be nice if we could still keep the global id abstraction, just not make it a scalar Would prs on this be accepted? I would like to contribute!
Unknown User
Unknown User5mo ago
Message Not Public
Sign In & Join Server To View
Aryan Iyappan
Aryan IyappanOP5mo ago
Could we redo the API such that the globalID.resolve_node and globalID.resolve_node_sync methods are separate, standalone functions? @bellini 🤔
Unknown User
Unknown User5mo ago
Message Not Public
Sign In & Join Server To View
Aryan Iyappan
Aryan IyappanOP5mo ago
Sure, at the top of my head, I'm thinking, we separate the resolve_node and resolve_node_sync methods into standalone functions But then GlobalID would be nothing else but a class with a couple of methods- including from_id So that raises a question- why not make the relay node types return the ID type directly itself? As in other implementations such as graphql-relay-js?? But then again, this would be a major change and would require core Dev approval, any inputs guys?
Unknown User
Unknown User5mo ago
Message Not Public
Sign In & Join Server To View
Aryan Iyappan
Aryan IyappanOP5mo ago
hey @rodaan can you show me the logs of the TypeError? 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),
)
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
Unknown User
Unknown User5mo ago
Message Not Public
Sign In & Join Server To View
Aryan Iyappan
Aryan IyappanOP5mo ago
Um, not really, you just need to define a new scalar (as mentioned above) and use it consistenly within the schema Don't use strawberry.ID in the schema after defining your own ID scalar
Unknown User
Unknown User5mo ago
Message Not Public
Sign In & Join Server To View
Aryan Iyappan
Aryan IyappanOP5mo ago
hey, are you using django by any chance?
Unknown User
Unknown User5mo ago
Message Not Public
Sign In & Join Server To View
Want results from more Discord servers?
Add your server