-
Notifications
You must be signed in to change notification settings - Fork 113
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 prepare
should generate binding initializer
#166
Comments
First, the basic use case without env vars: So let's take the following projects:
app:
schemaPath: src/schema.graphql
extensions:
endpoints:
default: http://localhost:4000
database:
schemaPath: src/generated/prisma.graphql
extensions:
prisma: database/prisma.yml
prepare-binding:
output: src/generated/prisma.ts
generator: prisma-ts
bahnhof:
schemaPath: src/generated/bahnhof.graphql
extensions:
endpoints:
default:
url: 'https://api.deutschebahn.com/free1bahnql/v1/graphql'
headers:
Authorization: Bearer myToken
prepare-binding:
output: src/generated/bahnhof.ts
generator: binding-ts To use these bindings in my code, I will need the the following for const link = new HttpLink({ uri, fetch })
const middlewareLink = (operation, forward) => {
console.log('operation', operation)
if (authorizationToken) {
operation.setContext(context => ({
...context,
headers: {
...context.headers,
Authorization: `Bearer ${authorizationToken}`
}
}))
}
return forward(operation)
}
const executableSchema = makeRemoteExecutableSchema({
schema: fs.readFileSync('src/generated/bahnhof.graphql', 'utf-8'),
link: ApolloLink.from([middlewareLink, link]),
});
const binding = new Binding({ schema: executableSchema }) And the following for const binding = new Prisma({
endpoint: 'https://eu1.prisma.sh/public-patternraccoon-961/my-service/dev',
secret: 'mysecret123', // specified in database/prisma.yml
debug: true, // log all GraphQL queries & mutations
}), Now if import { initDatabaseBinding, initBahnhofBinding } from 'src/generated/initBindings.ts'
const server = new GraphQLServer({
typeDefs: './src/schema.graphql',
resolvers,
context: req => ({
...req,
db: initDatabaseBinding(),
bahnhof: initBahnhofBinding()
}),
}) |
We've just released a new version and an alpha release channel for GraphQL CLI - In order to receive schemas the new new GraphQL Config which let's you specify multiple schemas from any source possible. I want to ask the people on this issue, in that case, why would you need the Checkout new instructions and the migration guide and we will be happy to hear your feedback during the alpha period! Feel free to contact us by opening an issue or using our Discord channel; |
I've posted the wrong Discord link, this is the correct one: https://discord.gg/xud7bH9 |
This command is no longer supported in 4.0.0. Closing |
Currently,
graphql prepare
generates the static binding class, but it doesn't generate the initialization part of it (e.g.new Binding(...)
). This means you have to manually duplicate the endpoint, headers and schema location in code.To improve this workflow, the
graphql prepare
command could generate this for you.Now the naive implementation would take whatever
graphql-config
comes up with, and use that. However, there are two catches here.First,
graphql-config
will resolve a prisma endpoint through the prisma extension, so it will have an actual endpoint URL and authorization header. Code generation however, should useprisma-binding
, notgraphql-binding
, because of additional features for Prisma.Second,
graphql-config
resolves environment variables. However, if someone is using environment variables in their.graphqlconfig
, it's highly likely that they would also want to use env vars in the code.The implementation proposal (that will follow) should take these two points into account.
The text was updated successfully, but these errors were encountered: