AE
Ash Elixir•2y ago
zorn

Do I have to manually make a `node` query in Absinthe to honor Global Object Identification?

I am using a SvelteKit library called Houdini to consume a GraphQL endpoint I am creating in Ash. I've intentionally marked my graphql, queries, list with relay?: true per the docs: https://ash-hq.org/docs/dsl/ash-resource#graphql-queries-list-relay- While pulling the schema for the frontend code, I get this error:
npx houdini generate -l full
šŸŽ© Generating runtime...
āš ļø Your project defines a Node interface but it does not conform to the Global Identification Spec.

If you are trying to provide the Node interface and its field, they must look like the following:

interface Node {
id: ID!
}

extend type Query {
node(id: ID!): Node
}

For more information, please visit these links:
- https://graphql.org/learn/global-object-identification/
- https://houdinigraphql.com/guides/caching-data#custom-ids
npx houdini generate -l full
šŸŽ© Generating runtime...
āš ļø Your project defines a Node interface but it does not conform to the Global Identification Spec.

If you are trying to provide the Node interface and its field, they must look like the following:

interface Node {
id: ID!
}

extend type Query {
node(id: ID!): Node
}

For more information, please visit these links:
- https://graphql.org/learn/global-object-identification/
- https://houdinigraphql.com/guides/caching-data#custom-ids
My observation is that my AshGraph is generating the
interface Node {
id: ID!
}
interface Node {
id: ID!
}
part just fine, but I do not see the
extend type Query {
node(id: ID!): Node
}
extend type Query {
node(id: ID!): Node
}
Is the expectation that I should have to write a manual node query and resolver inside the Absinthe schema file such that my graph honored the Global Object Identification spec? Or is there someway to nudge AshGraph to generate this for me?
10 Replies
ZachDaniel
ZachDaniel•2y ago
šŸ¤” I believe you'll need to make that yourself. You can add a custom query into the absinthe spec directly With that said, is the idea that you can get any instance of anything using just an id?
zorn
zornOP•2y ago
I think so. It uses a spread thing (not sure the right name) to id the type. https://relay.dev/docs/guides/graphql-server-specification/#object-identification
query RebelsRefetchQuery {
node(id: "RmFjdGlvbjox") {
id
... on Faction {
name
}
}
}
query RebelsRefetchQuery {
node(id: "RmFjdGlvbjox") {
id
... on Faction {
name
}
}
}
inline fragment I think is the name. https://graphql.org/learn/queries/#inline-fragments
ZachDaniel
ZachDaniel•2y ago
There is some difficulty there, because you could do this:
query RebelsRefetchQuery {
node(id: "RmFjdGlvbjox") {
id
... on Faction {
name
}
...on SomethingElse {
name
}
}
}
query RebelsRefetchQuery {
node(id: "RmFjdGlvbjox") {
id
... on Faction {
name
}
...on SomethingElse {
name
}
}
}
So unless you know how to figure out what type of thing you're looking for for every type of thing that can be fetched using just the id (like using prefixed uuids or something) then that would be problematic
zorn
zornOP•2y ago
I think the relay standard is to base64 encode the type and the id like car:123 into that string.
ZachDaniel
ZachDaniel•2y ago
oh, how interesting well, its not doing that currently šŸ™‚ we could add that feature into the node behavior relatively easily
zorn
zornOP•2y ago
But the curious thing is, the GraphQL library I'm using is not outright a Relay thing, but it demands "conform to the Global Identification Spec" and then links to that graphql.org page. -- Being a noob I'm not sure where to look for what atm.
ZachDaniel
ZachDaniel•2y ago
hm....pretty interesting seems like there should be a way to bypass that warning well, error it looks like or you could just add the query and have it raise an error using absinthe directly I mean
zorn
zornOP•2y ago
I think I might be able to configure Houdini to look for other fields to resolve.
No description
zorn
zornOP•2y ago
I'm going to close this with the workaround for future searches that, yes you can do this, but currently, it would be by hand in Absinthe.
ZachDaniel
ZachDaniel•2y ago
Yeah, that makes sense. It sounds like a nice feature to be able to enable that global node in ash_graphql

Did you find this page helpful?