Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more customizable pattern for tag #423

Closed
aspirisen opened this issue Apr 12, 2021 · 2 comments · Fixed by #1226
Closed

Add more customizable pattern for tag #423

aspirisen opened this issue Apr 12, 2021 · 2 comments · Fixed by #1226

Comments

@aspirisen
Copy link

Thanks to TS new feature Template Literal Types it becomes possible to parse the query on type level, at least not complex one. However, it is not possible to get type of tagged literal because it is always TemplateStringsArray, but it is possible to use plain functions instead gql('query { data }'). So the correct types will be inferred in TS itself, and the autocomplete will be provided by this plugin.

Also, it would be good to add possibility to provide autocomplete in types just as bonus for edge cases, i.e.
type Data = Query<'query { data }'>

It would be good to specify more complex pattern like start with gql(' and ends with ') for functions and to cover case with types you could set start with Query<' and ends with '>, or array of patterns. So we need just to specify the pattern which includes graphql content.

I think it could close this issues as well
#117
#53

@Quramy
Copy link
Owner

Quramy commented Apr 13, 2021

I agree "adding more complex tag pattern" .

Because some GraphQL clients don't use template literal tag function.

For example, with octokit/graphql.js :

const { repository } = await graphql(
  `
    {
      repository(owner: "octokit", name: "graphql.js") {
        issues(last: 3) {
          edges {
            node {
              title
            }
          }
        }
      }
    }
  `,
  {
    headers: {
      authorization: `token secret123`,
    },
  }
);

But I will not care TypeScript Template Literal Types pattern (e.g. Query<"query { data }"> ).

But I will not use this in my plugin because I think lexing / parsing queries should be responsible for graphql-js . And recursive descent parser with string type literal can exceed TypeScript's recursive type limitation.

#117 (comment)

@aspirisen
Copy link
Author

@Quramy about

But I will not care TypeScript Template Literal Types pattern (e.g. Query<"query { data }"> ).

I don't mean to actually infer type or whatever, just when you specify the pattern do not ignore ts types if they are matched by the pattern. I.e. here type Data = Query<'query { data }'> there is no some predefined Query type that cause some special behavior of ts-graphql-plugin. So as i understand the task of the plugin is match part of the file text, parse it as GraphQL and provide autocomplete.

So yes, i agree that this plugin should not provide some types inference out of the box, but delegate it to some other third party libraries. However, it would be good to have autocomplete in such cases

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants