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

typedGql not type safe? #339

Closed jetaggart closed 1 year ago

jetaggart commented 2 years ago

I'm using zeus with apollo and it seems that I can pass any arbitrary key to typedGql which will compile but end up as a 400. Am I missing something that makes typedGql fully type safe?

--

For example, I have a query like this:


const plants = typedGql("query")({
  plants: {
    __typename: true,
    id: true,
    createdAt: true,
    description: true,
    hello: true
  }
})

And a schema like this:

### This file was generated by Nexus Schema
### Do not make changes to this file directly

"""
A date-time string at UTC, such as 2007-12-03T10:15:30Z, compliant with the `date-time` format outlined in section 5.6 of the RFC 3339 profile of the ISO 8601 standard for representation of dates and times using the Gregorian calendar.
"""
scalar DateTime

type Plant {
  createdAt: DateTime!
  description: String!
  id: Int!
  url: String!
}

type Query {
  plants: [Plant!]!
}

Notice the hello: true line in the query. This typechecks yet causes a 400 on the backend since hello is unexpected. How can I make this typesafe and reject hello?

jetaggart commented 2 years ago

What's even stranger is if I remove the id field then it no longer typechecks...

This compiles:

Screen Shot 2022-09-24 at 1 56 52 PM

This does not:

Screen Shot 2022-09-24 at 2 01 10 PM
aexol commented 1 year ago

I have an idea how to fix that but I already tried 999 times so maybe

aexol commented 1 year ago

almost fixed

CryptoGraffe commented 1 year ago

Any progress on this?

imbroyury commented 1 year ago

@aexol might this approach help somehow? https://stackoverflow.com/a/57117594

jeenkhoorn commented 1 year ago

I'm also interested in type safety for typedGql. On version 5.3.1 I'm still able to request an arbitrary property without errors. Is this issue actually completed/resolved or is it just closed?

jetaggart commented 1 year ago

I don't believe it got resolved, I was just cleaning up issues I've opened that seem stale.

IceBlizz6 commented 12 months ago

I also commented on https://github.com/graphql-editor/graphql-zeus/issues/232 Seems like these issues are (almost?) identical. Both these issues were closed with the #381 pull request.

I'm still able to request arbitrary fields with the most recent version 5.3.2 Is anyone able to confirm that this PR actually solved the issue? and if so then can i get a working sample project?