graphql-zeus icon indicating copy to clipboard operation
graphql-zeus copied to clipboard

typedGql not type safe?

Open jetaggart opened this issue 2 years ago • 1 comments

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 avatar Sep 24 '22 19:09 jetaggart

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

jetaggart avatar Sep 24 '22 20:09 jetaggart

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

aexol avatar Dec 13 '22 15:12 aexol

almost fixed

aexol avatar Dec 13 '22 15:12 aexol

Any progress on this?

CryptoGraffe avatar Mar 14 '23 16:03 CryptoGraffe

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

imbroyury avatar Jun 10 '23 05:06 imbroyury

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?

jeenkhoorn avatar Oct 13 '23 14:10 jeenkhoorn

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

jetaggart avatar Oct 14 '23 03:10 jetaggart

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?

IceBlizz6 avatar Nov 07 '23 21:11 IceBlizz6