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

GraphQL Aliases #22

Open
travis-r6s opened this issue Nov 1, 2019 · 4 comments
Open

GraphQL Aliases #22

travis-r6s opened this issue Nov 1, 2019 · 4 comments

Comments

@travis-r6s
Copy link

travis-r6s commented Nov 1, 2019

Is there anyway to specify an alias in the query object?

My use case - I have a list of product ID's that I want to fetch from shopify. I want to fetch the products all at once, so would usually programatically create a gql string like so:

query products {
  [id]: product (...) {..}
  [id]: product (...) {..}
  [id]: product (...) {..}
  [id]: product (...) {..}
  ...
}

I can create an object similar to the above to pass into query, but obviously can't have multiple product: [{}] as they are duplicate keys. Or perhaps there is a way to create a chain with a number of queries?

Hope that makes sense..?

@helios1138
Copy link
Owner

Aliases are not supported right now, because I couldn't think of a nice syntax that would allow describing aliases in TS, while also preserving auto-completion support :)

Suggestions are welcome

@pierissimo
Copy link

this looks reasonable to me, and also it would be easy to preserve typing and intellisense

client.query({
  originalQueryName: {
    __alias: {
      newQueryName: {
        field: true,
      },
    },
  },
})

@Gozala
Copy link

Gozala commented May 20, 2021

Maybe something along the lines of:

client.aliased.query({
   first: {
      product: [input, {
      }]
   },
  second: {
     product: [input, {
     }]
  }
})

I think at type level it should be possible to turn QR into union of records each containing a single field providing type for the aliased field. Return also could be type mapped to corresponding Qs.

@Nevvulo
Copy link

Nevvulo commented Jul 15, 2021

I've just ran into a situation where I need to use aliases in my query and I would love to see this added. I would've expected something similar to how on_[Model] works at the moment, for example the key would be: alias_[aliased name]_[real field name] (in this case alias_specificProduct_product) and the value would be a normal query object. I understand there's no alias keyword in GraphQL so it may not read like the original but feels intuitive enough to fit into an existing query. But I'm not fussed and I think both suggestions above are good as well 🙂

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

5 participants