Closed marvinhagemeister closed 7 years ago
You need to send this official "introspection query" from graphql-js to the running server, then save the result: https://github.com/graphql/graphql-js/blob/master/src/utilities/introspectionQuery.js
@stubailo Awesome! I got it working now by manually saving the response into the schema. Is there any way to automate this without having to manually query the server when the type definition change?
I'm definitely open to suggestions, but we haven't come up with a really simple solution yet, especially one that deals with the server running or not running.
@schickling was working on a solution with https://github.com/graphcool/graphql-config
Thanks for pinging me @stubailo. Would love to hear your feedback on graphql-config @marvinhagemeister!
@schickling can you comment on how one would use graphql-config together with eslint-plugin-graphql? It says pending in readme and also does that mean I can just remove the line locally configuring schema.json?
Hey @tonyxiao. @stubailo and I are still in the process of integrating eslint-plugin-graphql with graphql-config. I'll make sure to ping you here again, as soon as it's available!
Got it, please also mention when it's compatible with language-graphql
too. Looking forward to this.
graphql-config
sounds awesome. Here's a little NodeJS script I've been using in the meantime to update a local json file from a running GraphQL server. https://gist.github.com/rmarscher/ea338015c0d80da06c46009030128a07
closing this for now. let us know when eslint-plugin-graphql
can use graphql-config
!
Hey @schickling just came across this thread and gave a shot to your fork and it's working. I know there are some loose ends but maybe submitting a PR to the original repo would move the ball forward?
Is there any update on this? The gist provided end in infinite loop for me ;( Thanks!
I am using this
import 'isomorphic-fetch';
import { parse, introspectionQuery } from 'graphql';
import { createApolloFetch } from 'apollo-fetch';
import fs from 'fs';
const apolloFetch = createApolloFetch({ uri: `https://www.blabla.com/api/graphql` });
const query = parse(introspectionQuery);
const schemaPath = `${__dirname}/../../schema.json`;
apolloFetch({ query })
.then((result) => {
const schema = JSON.stringify(result, null, ' ');
return new Promise(resolve => fs.writeFile(schemaPath, schema, 'utf8', resolve));
})
.catch((err) => {
console.error(err);
});
I've answered this question over here: https://stackoverflow.com/a/42010467/2418739
Here's how I do it programmatically:
import gql from 'graphql-tag';
// Instance of ApolloClient
import client from '../client';
import { introspectionQuery as rawIntrospectionQuery, buildClientSchema } from 'graphql/utilities';
const introspectionQuery = gql(rawIntrospectionQuery);
const getSchema = async (client) => {
const { data } = await client.query({ query: introspectionQuery });
const schema = buildClientSchema(data);
return schema;
};
getSchema(client)
.then(schema => /* schema is an instance of GraphQLSchema */);
Hi Team,
I am trying to get schema of graphql using introspection query. However it's giving me below error multiple times:
GraphQL error: Null value resolved for non-null field `__typename`
GraphQL error: Null value resolved for non-null field `__typename`
Can you please help?
I am using below code to fetch the schema.
npm packages version
"apollo-cache-inmemory": "1.6.2",
"apollo-client": "2.6.0",
"apollo-link-http": "1.5.15",
"graphql": "14.3.1",
"graphql-tag": "2.10.1",
"node-fetch": "2.6.0",
"typescript": "3.6.2"
import { createHttpLink } from 'apollo-link-http';
import { InMemoryCache } from 'apollo-cache-inmemory';
import ApolloClient from 'apollo-client';
import gql from 'graphql-tag';
import fetch from 'node-fetch';
let query = "query IntrospectionQuery{__schema {types {name description fields { name type { ofType {name}}}}}}";
let subgraphEndPoint = 'https://api.thegraph.com/subgraphs/name/ensdomains/ens';
let link = createHttpLink({ uri: subgraphEndPoint, fetch: fetch as any });
let cache = new InMemoryCache();
let variables = {}
let apolloClient = new ApolloClient({ link, cache });
let gqlQuery = gql(query);
apolloClient.query({query: gqlQuery,variables,fetchPolicy: 'no-cache'}).then(console.log);
You need to send this official "introspection query" from graphql-js to the running server, then save the result: https://github.com/graphql/graphql-js/blob/master/src/utilities/introspectionQuery.js
Is now : https://github.com/graphql/graphql-js/blob/main/src/utilities/getIntrospectionQuery.ts
I'm a bit confused by the various ways to define a graphql schema and which is the right one for this plugin. I have a working apollo server instance, where the schema is defined via type definitions:
But how do I get the introspection query result as mentioned in the README of this repo? I'm a bit confused on what the property
schemaJson
should look like inside the.eslintrc.js
. Are there any examples? The ones I've found so far seem to redeclare the schema definitions specifically for eslint.