graphql-editor / graphql-zeus

GraphQL client and GraphQL code generator with GraphQL autocomplete library generation ⚡⚡⚡ for browser,nodejs and react native ( apollo compatible )
https://graphqleditor.com/docs/tools/zeus/index/
MIT License
1.94k stars 105 forks source link

How to use variables post 5.0? #323

Closed RoryO closed 2 years ago

RoryO commented 2 years ago

I was using Zeus completely fine pre 5.0. I usually wrote queries with variables as such

await Chain('http://foo.us', headers: {})('mutation')({
  insert_foo_one: [{
    object: {
      bar: $`bar`
    }
  }, {
    id: true
  }]
}, {
  operationName: 'InsertFooWithBar',
  variables: {
    bar: barId
  }
});

This used the $ template function, which used to be in the generated schema defined as

export const $ = (t: TemplateStringsArray): any => `ZEUS_VAR$${t.join('')}`;

I have been using 5.1 for a while, and I never regenerated the schema yet, things still worked just as before. So I was using a generated schema from 4 with 5.1 without issue. Now, when I regenerate the schema with 5.1.2 using npx zeus https://foo.us ./src --node, the $ template tag is missing. The documentation about variables talks about the useZeusVariables and then doesn't use it in any of the examples. The example also uses a $ function like card: $('card'), but the example mutation doesn't have anything matching the symbol 'card', so I'm extra lost. Further, the example page has import { Gql, $ } from './zeus';, however my generated schema file does not have any export named $, so now I'm super omega lost. What's the intended thing to do here?

RoryO commented 2 years ago

Bit of an update, dependabot never gave me a PR for 5.1.7, so I was using 5.1.2. Updating to 5.1.7 gets me further as there is now a $ function exported. I think I can infer what to do from here with the new $ function, even though it isn't documented. This is a pretty rough migration, I think I have a few hundred variables using the $ template tag.

vxm5091 commented 2 years ago

@RoryO For what it's worth, there's a good example of useZeusVariables here:

281

RoryO commented 2 years ago

Thanks, I don't think that's entirely right either. Last I tried, the new $ function required two parameters, the name of the variable and the graphql type. The second seemed unnecessary work since whatever process assigns typescript variables to the gql variables already knows the gql type. We shouldn't have to specify it again. So I'm thinking we're not supposed to use the $ function anymore and it's probably internal. At any rate I'm using the last 4.x release until all of these bumps clear.