When accessing a GraphQL API, you typically do this:
apolloClient.mutate(gql`
mutation MyMutation($name: String!, $password: $String!) {
insert_user(objects: [{name: $name, password: $password}]) {
returning {
id
}
}
}`,
variables: {
name: 'kevin',
password: 'xxx'
}
)
It's verbose, but if you also use TypeScript, a decent amount of manual type declarations are needed for type safety and that makes it even more verbose:
type OperationResult = {
insert_user: {
returning: Array<{ id: string }>
}
}
type OperationVariables = {
name: string
password: string
}
apolloClient.mutate<OperationResult, OperationVariables>(gql`
mutation MyMutation($name: String!, $password: $String!) {
insert_user(objects: [{name: $name, password: $password}]) {
returning {
id
}
}
}`,
variables: {
name: 'kevin',
password: 'xxx'
}
)
I wonder if it's possible/practical to generate a JS/TS/Go SDK with built-in types from a random GraphQL endpoint, given that you are able to access its schema file.
So instead of using DSL, you use an actual language instead:
const client = require('./generated-client')
await client.insert_user({
objects: [{ name: 'kevin', password: 'xxx' }],
select: {
returning: {
id: true
}
}
})
And it's type-safe by default.
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too