Mayank1791989 / gql

112 stars 19 forks source link

Use Introspection Query as Schema #65

Open arahansen opened 7 years ago

arahansen commented 7 years ago

I was wondering if its possible to expand the functionality of this tool to be able to ingest an introspection query json similar to how eslint-plugin-graphql handles validation.

For my project, I don't always have the *.gql schema types available locally, but I'm able to grab the introspection query json.

I'd be happy to take a look at adding support if I could maybe get pointed in the right direction for where to start digging in!

Mayank1791989 commented 7 years ago

For my project, I don't always have the *.gql schema types available locally, but I'm able to grab the introspection query json.

You can always convert introspection query json to schema.graphql

import { printSchema, buildClientSchema } from 'graphql';
const schema = printSchema(buildClientSchema(introspectionQueryJSON));
// write schema to schema.graphql and use it

I'd be happy to take a look at adding support if I could maybe get pointed in the right direction for where to start digging in!

The support was intentionally not added as this package also support writing schema files and I do not want to complicate .gqlconfig structure.

DogsForArms commented 6 years ago

Was there ever support added for this? I think it would be extremely nice to have.

ndonnellan commented 6 years ago

I don't know what graphql version the previous comments were referring to, but the proper command for at least graphql@0.13.2 is:

import { printSchema, buildClientSchema } from 'graphql';
const introspectionQueryJSON = //getitfromsomewhere...
const schema = printSchema(buildClientSchema(introspectionQueryJSON));
// not introspectionQueryJSON.__schema

// write schema to schema.graphql and use it

the __schema property is accessed from within buildClientSchema.

Mayank1791989 commented 6 years ago

@ndonnellan Thanks, I have fixed the comment.