After following the steps in the getting started guide, I now have a code file that was generated from an existing federated graph that has been deployed. The generated code includes:
export type Query = {
__typename?: 'Query';
customerById: Customer;
// not a complete list
Now, I want to use this query to get a specific customer with ID
5a5e5aca-5512-4fb7-bde4-03fadf88e777
. The documentation indicates writing new GQL code, for example:
const allFilmsWithVariablesQueryDocument = graphql(/* GraphQL */
query allFilmsWithVariablesQuery($first: Int!) {
allFilms(first: $first) {
edges {
node {
...FilmItem
...
const { data } = useQuery(allFilmsWithVariablesQueryDocument, { variables: { first: 10 } })
This approach seems to suggest using local GQL to query remote GQL?
Instead, I would prefer a simpler method like
const customer = runQuery(Queries.customerById, {id: '5a5e5aca-5512-4fb7-bde4-03fadf88e777' })
. This is similar to how Zeus functions (refer to "Query with Zeus Chain Client" section on Zeus website).
I am looking for autocomplete functionality in queries. While Zeus offers this feature to some extent, it has certain dependencies like global fetch and Websocket which are not ideal as they require corrections in the generated code. Is this capability available in @graphql-codegen? Am I misunderstanding something here? If it's possible to utilize Query.customerById
within a function, how can this be achieved?