GraphQL :type, prefix based on Context?

In the example docs, we have something like the following:
defmodule Helpdesk.Support.Ticket do
...omitted...
graphql do
type :ticket
end
end
defmodule Helpdesk.Support.Ticket do
...omitted...
graphql do
type :ticket
end
end
So, the following introspection query would return Ticket as a type.
{
__schema {
types {
name
}
}
}
{
__schema {
types {
name
}
}
}
So, given a totally made up hypothetical, if we had another Ash API with a resource Amusement.Parks.Ticket , included in the same Ash GraphQL Schema... wouldn't the two Ticket graphql names clobber each other? So, is there a way to automatically prefix the resource with a context/api based name? To get graphql like HelpdeskSupportTicket and AmusementParksTicket ? Or is it up to the application developer to explicitly define type :helpdesk_support_ticket and type :amusement_parks_ticket ?
3 Replies
ZachDaniel
ZachDaniel2y ago
You could write an extension that would do that, yes I probably wouldn't suggest it though, TBH You'll get a compile time error about duplicate types so you can use that to see that you've created a conflict But it is possible yes to write an extension that prefixes a resource's graphql type with some configured value based on the api you use it with, that kind of thing
Ben RMX
Ben RMXOP2y ago
Ok. To recap what I think you're saying is that 1. Just having type :ticket w/o extension will result in compile time error 2. That, it is possible to write extension to both prefix the GraphQL type (in GraphQL schema) and to avoid a compile time problem with multiple type :ticket 3. That you suggest against writing an extension, and that just manually prefixing (e.g. type :helpdesk_support_ticket) is the easier/safer bet. Did I understand correctly? If so, thanks! 👍
ZachDaniel
ZachDaniel2y ago
yes 👍

Did you find this page helpful?