dotansimha / graphql-code-generator-community

MIT License
114 stars 144 forks source link

Generate TS SDK with boolean specifiers that generates query document at runtime? #163

Open dotansimha opened 2 years ago

dotansimha commented 2 years ago

Note: this is an experiment

sdk.query({
  user: { id: true, name: true, profile: { age: true }}
})

for union/interface:

sdk.query({
    search({ term: ".." }) => ({
        __User: { name: true },
        __Node: { id: true }
    })
})

Goals:

n1ru4l commented 2 years ago

it is totally possible, that an object type has a __User or __Node field. Maybe we should use symbols instead?

sdk.query({
    search({ term: ".." }) => ({
        [sdk.type.User]: { name: true),
        [sdk.type.Node]: { id: true }
    })
})

Alternative API with spread usage that "resembles" inline fragment spreads within graphql documents.

sdk.query({
    search({ term: ".." }) => ({
        ...sdk.on.User({ name: true }), // this function resturns { [sdk.type.User]: { name: true } }
        ...sdk.on.Node({ id: true })
    })
})