-
Notifications
You must be signed in to change notification settings - Fork 525
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
Generate .graphql schema file #378
Comments
Hey! It's definitely on the roadmap, although everything we've run into so far has been usable with the output from https://hexdocs.pm/absinthe/Mix.Tasks.Absinthe.Schema.Json.html Does that task not work for some of your tools? |
I'm pretty fond of VSCode and the current plugin for graphql. https://github.com/kumarharsh/graphql-for-vscode uses a service that only works with .graphql files. The better solution is to create a plugin that implements Facebooks Own reference language server. https://github.com/graphql/graphql-language-service/issues/7 But it might still make sense to be able to output .graphql files to accommodate future use cases. |
Yeah, this is a roadmap item for (currently slated) v1.5, when using a |
@Aleksion just curious, do you have any issues with https://github.com/apollographql/apollo-codegen? I get along quite well with apollo-codegen and absinthe. |
Nope, Codegen works just fine. The problem has been my graphql vscode plugin. I'm running a script to convert it currently, so my plugin works (using the official javascript library) cp "../MY_ELIXIR_APP/schema.json" "./src/app/schema.json"
gql-gen --file ./src/app/schema.json --template typescript --out ./src/app/queries/schema.d.ts "./src/**/*.ts"
node ./bash/graphql.js --src "./src/app/schema.json" --out "./src/app/schema.graphql" and then the javascript file: const { buildSchema, buildClientSchema, printSchema, introspectionQuery } = require("graphql")
const fs = require("fs")
let src = null
let out = null
process.argv.forEach(function (val, index, array) {
if (val === "src") {
src = array[index + 1]
}
switch (val) {
case "--src":
src = array[index + 1]
break;
case "--out":
out = array[index + 1]
break
}
});
if (!src) {
console.error("must provide src path")
return
}
if (!out) {
console.error("must provide out path")
return
}
function writeSchema(src, out) {
const fileContent = fs.readFileSync(src, "utf-8")
if (!fileContent) {
console.error("no schema found")
return
}
const { data } = JSON.parse(fileContent)
const clientSchema = buildClientSchema(data)
const graphqlSchemaString = printSchema(clientSchema)
fs.writeFileSync(out, graphqlSchemaString)
}
writeSchema(src, out) I'm using gql-gen though, but apollo codegen worked fine as far as I remember |
A .graphql schema would also be useful for the following scenario: |
Here’s a useful tool to get an SDL (.graphql) representation of your schema via converting the result of introspection; this might help until SDL export (& import) support arrives in Absinthe v1.5: https://github.com/graphcool/get-graphql-schema |
There is a mix task now to generate the SDL 🎉. See https://hexdocs.pm/absinthe/1.5.0-beta.2/Mix.Tasks.Absinthe.Schema.Sdl.html#content This issue can be closed :) |
Hi,
Besides generating the introspection result is it possible to generate a .graphql schema?
Some of the tooling I usually work with with graphql requires .graphql schema to operate properly. There are some outdated js tools to convert from the introspection result, but it would be much nicer to do it directly from elixir.
The text was updated successfully, but these errors were encountered: