Created
May 7, 2021 13:14
-
-
Save kyledetella/c671ca6335fbfd9e6aa3db97db0c212f to your computer and use it in GitHub Desktop.
Get SDL from GraphQL introspection query
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { | |
buildClientSchema, | |
buildSchema, | |
getIntrospectionQuery, | |
GraphQLSchema, | |
printSchema, | |
} from "graphql"; | |
import fetch from "node-fetch"; | |
const GRAPHQL_API_URL = ""; | |
const GRAPHQL_API_AUTH_TOKEN = ""; | |
(async () => { | |
const resp = await fetch(GRAPHQL_API_URL, { | |
method: "POST", | |
headers: { | |
Authorization: `Basic ${GRAPHQL_API_AUTH_TOKEN}`, | |
"Content-Type": "application/json", | |
}, | |
body: JSON.stringify({ query: getIntrospectionQuery() }), | |
}); | |
const { data } = await resp.json(); | |
// Convert to SDL | |
console.log(printSchema(buildClientSchema(data))); | |
// Get GraphQLSchema type | |
console.log(buildSchema(data)); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment