gql icon indicating copy to clipboard operation
gql copied to clipboard

Use Introspection Query as Schema

Open arahansen opened this issue 7 years ago • 4 comments

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!

arahansen avatar Oct 09 '17 00:10 arahansen

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.

Mayank1791989 avatar Oct 09 '17 17:10 Mayank1791989

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

DogsForArms avatar Dec 09 '17 23:12 DogsForArms

I don't know what graphql version the previous comments were referring to, but the proper command for at least [email protected] 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.

ndonnellan avatar Nov 01 '18 14:11 ndonnellan

@ndonnellan Thanks, I have fixed the comment.

Mayank1791989 avatar Nov 01 '18 15:11 Mayank1791989