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

Support for GraphQL aliases take 2 #55

Closed
jasonkuhrt opened this issue Mar 26, 2021 · 7 comments
Closed

Support for GraphQL aliases take 2 #55

jasonkuhrt opened this issue Mar 26, 2021 · 7 comments

Comments

@jasonkuhrt
Copy link

jasonkuhrt commented Mar 26, 2021

I thought I had a use-case for #10 but then didn't. Still interested in having aliases supported though.

I can't remember right now but if we can make the types "extensible" (records with known fields) then we could treat ANY UNKNOWN key as being an alias. Its type would be a union of objects for each peer field, where each object accepts ONLY ONE.

{
  things: [ 
    {}, 
    {
      foo: true,
      foo2: { foo: true },
      bar2: { bar: { /* selection set */ } },
      qux2: { qux: [{/* args */},{ /* selection set */ }]}
    }
  ]
}

I can't remember right now but if we can make the types "extensible" (records with known fields) then we could treat ANY UNKNOWN key as being an alias.

If not, then, unfortunately:

{
  things: [ 
    {},
    {
      foo: true,
    }, 
    {      
      foo2: { foo: true },
      bar2: { bar: { /* selection set */ } },
      qux2: { qux: [{/* args */},{ /* selection set */ }]}
    }
  ]
}

I am pretty sure that what will happen is the record's known fields vs extensible ones will have to share the same type, and that is NOT what we want here. Thus, a third parameter would be needed.

@remorses
Copy link
Owner

The problem of doing aliases is that typing becomes a nightmare, as you can see the current type for fields selection is already very complex, adding more will make type checking and completion slower and probably create new bugs

@jasonkuhrt
Copy link
Author

jasonkuhrt commented Mar 29, 2021

Yeah I believe that. I think type tests might be able to help with regard to testing. Here is a minor example of some we did in Nexus https://github.com/graphql-nexus/nexus/blob/main/src/typegenTypeHelpers.spec.types.ts.

Basically its TS type-level logic that if fails will raise compile errors during build and thus acts like a test would in CI.

I'm not sure how applicable that is here though.

@remorses
Copy link
Owner

I already do test types 👍

What i am saying is that the alias feature is not worth the additional complexity

@thelinuxlich
Copy link

@jasonkuhrt
Copy link
Author

Aliases are needed to workaround this weird issue graphql/graphql-js#522. I am not fully convinced/understand it but alas it seems like a GQL limitation that will not be going away.

@thdxr
Copy link

thdxr commented May 10, 2022

are aliases planned at all? we're trying to figure out if we should use genql or zeus and it'll likely be the deciding factor

@jasonkuhrt
Copy link
Author

Another use-case for aliases. We need to fetch workspace usage twice, for the current and the previous cycle. This seems like a perfect use-case of aliases:

CleanShot 2023-12-06 at 12 41 19@2x

For the time being, batching offers a workaround: https://genql.dev/docs/usage/batching-queries, but I don't consider it ideal.

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

No branches or pull requests

4 participants