Newsletter
TechAnV Blog
Get updates on security engineering, Rust, eBPF, and DevSecOps. No spam, unsubscribe anytime.
Check your inbox and click the confirmation link to complete your subscription.
get-graphql-schema#
The GraphQL schema language is a concise way to represent the available schema provided by a GraphQL endpoint. It looks something like this:
1type assets {2 url: String3 node_id: String4 name: String5 label: String6 content_type: String7 state: String8 created_at: String9 updated_at: String10 browser_download_url: String11 id: Int12 size: Int13 download_count: Int14 uploader: users15 release: releases16}17
18type assetsCollection {19 totalCount: Int20 pageInfo: PageInfo21 nodes: [assets]22 edges: [assetsEdge]23}You can retrieve a JSON version of this from the GraphQL server itself using the query at the bottom of this document.
But… if you want it back in readable text as shown above, you can use the get-graphql-schema tool. Run that like this:
1npx get-graphql-schema https://github-to-sqlite.dogsheep.net/graphqlIf the API requires authentication, use the --header option like this:
1npx get-graphql-schema https://api.github.com/graphql -h 'Authorization=Bearer XXX'Retrieving the schema as JSON using GraphQL#
I found this query using the network inspector against a GraphiQL instance (https://api.fly.io/graphql) that offered a “Schema” tab:
1query IntrospectionQuery {2 __schema {3 queryType {4 name5 }6 mutationType {7 name8 }9 subscriptionType {10 name11 }12 types {13 ...FullType14 }15 directives {16 name17 description18 locations19 args {20 ...InputValue21 }22 }23 }24}25fragment FullType on __Type {26 kind27 name28 description29 fields(includeDeprecated: true) {30 name31 description32 args {33 ...InputValue34 }35 type {36 ...TypeRef37 }38 isDeprecated39 deprecationReason40 }41 inputFields {42 ...InputValue43 }44 interfaces {45 ...TypeRef46 }47 enumValues(includeDeprecated: true) {48 name49 description50 isDeprecated51 deprecationReason52 }53 possibleTypes {54 ...TypeRef55 }56}57fragment InputValue on __InputValue {58 name59 description60 type {61 ...TypeRef62 }63 defaultValue64}65fragment TypeRef on __Type {66 kind67 name68 ofType {69 kind70 name71 ofType {72 kind73 name74 ofType {75 kind76 name77 ofType {78 kind79 name80 ofType {81 kind82 name83 ofType {84 kind85 name86 ofType {87 kind88 name89 }90 }91 }92 }93 }94 }95 }96}