query IntrospectionQuery { | |
__schema { | |
queryType { name } | |
mutationType { name } | |
subscriptionType { name } | |
types { | |
...FullType | |
} | |
directives { | |
name | |
description | |
args { | |
...InputValue | |
} | |
onOperation | |
onFragment | |
onField | |
} | |
} | |
} | |
fragment FullType on __Type { | |
kind | |
name | |
description | |
fields(includeDeprecated: true) { | |
name | |
description | |
args { | |
...InputValue | |
} | |
type { | |
...TypeRef | |
} | |
isDeprecated | |
deprecationReason | |
} | |
inputFields { | |
...InputValue | |
} | |
interfaces { | |
...TypeRef | |
} | |
enumValues(includeDeprecated: true) { | |
name | |
description | |
isDeprecated | |
deprecationReason | |
} | |
possibleTypes { | |
...TypeRef | |
} | |
} | |
fragment InputValue on __InputValue { | |
name | |
description | |
type { ...TypeRef } | |
defaultValue | |
} | |
fragment TypeRef on __Type { | |
kind | |
name | |
ofType { | |
kind | |
name | |
ofType { | |
kind | |
name | |
ofType { | |
kind | |
name | |
} | |
} | |
} | |
} |
This comment has been minimized.
This comment has been minimized.
Very useful, thanks for posting! |
This comment has been minimized.
This comment has been minimized.
Very helpful. Thanks. |
This comment has been minimized.
This comment has been minimized.
cheers |
This comment has been minimized.
This comment has been minimized.
Thanks! I used it to make this |
This comment has been minimized.
This comment has been minimized.
Thank you for your nice gist. According to graphql-js issue #1429, graphql-js v14 dropped support This Instead of above fields, we should use the query IntrospectionQuery {
__schema {
queryType {
name
}
mutationType {
name
}
subscriptionType {
name
}
types {
...FullType
}
directives {
name
description
args {
...InputValue
}
- onOperation
- onField
- onFragment
+ locations
}
}
} |
This comment has been minimized.
This comment has been minimized.
I was looking for the following when I came across this gist: const {introspectionQuery } = require('graphql'); |
This comment has been minimized.
This comment has been minimized.
npm install -g graphql-introspect
graphql-introspect URL > schema.graphql |
This comment has been minimized.
This comment has been minimized.
const path = require("path");
const fs = require("fs");
const fetch = require("node-fetch");
const {
getIntrospectionQuery,
printSchema,
buildClientSchema
} = require("graphql");
async function main() {
const introspectionQuery = getIntrospectionQuery();
const response = await fetch(
"https://<URL_HERE>/graphql",
{
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({ query: introspectionQuery })
}
);
const { data } = await response.json();
const schema = buildClientSchema(data);
const outputFile = path.join(__dirname, "./result.gql");
await fs.promises.writeFile(outputFile, printSchema(schema));
}
main(); |
This comment has been minimized.
This comment has been minimized.
@danstarns what is the query here? |
This comment has been minimized.
This comment has been minimized.
introspectionQuery is an exported member of graphql, the query is that. const { introspectionQuery } = require("graphql");
console.log(introspectionQuery); |
This comment has been minimized.
This comment has been minimized.
@danstarns thank you. |
This comment has been minimized.
This comment has been minimized.
The graphql reference implementation on JS has changed slightly and introspectionQuery is no longer exported as above. For newer versions of graphql (after graphql/graphql-js#2718), the above will break/not work, however, this seems to work after adapting to getIntrospectionQuery:
|
This comment has been minimized.
This comment has been minimized.
Good call updated |
This comment has been minimized.
This is awesome. Thanks @craigbeck!