Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env node
- const os = require('os');
- const request = require('request-promise-native');
- const fs = require('mz/fs');
- let hostname = os.hostname();
- let baseUrl = 'YOUR_BASE_URL';
- (async () => {
- let jwt = await getJwt();
- console.log("JWT Fetched");
- console.log("Getting Schema");
- let response = await request.post(baseUrl + '/graphql', {
- headers: {
- 'Content-Type': 'application/json',
- 'YOUR_HEADER+NAME': jwt
- },
- body: JSON.stringify({
- query: `
- query IntrospectionQuery {
- __schema {
- queryType { name }
- mutationType { name }
- subscriptionType { name }
- types {
- ...FullType
- }
- directives {
- name
- description
- locations
- args {
- ...InputValue
- }
- }
- }
- }
- 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
- ofType {
- kind
- name
- ofType {
- kind
- name
- ofType {
- kind
- name
- ofType {
- kind
- name
- }
- }
- }
- }
- }
- }
- }
- }`
- })
- });
- await fs.writeFile('graphql.schema.json', JSON.stringify(JSON.parse(response), null, "\t"));
- console.log("Schema Updated!");
- })();
- async function getJwt() {
- let username = 'YOUR_USERNAME';
- let password = 'YOUR_PASSWPRD';
- let response = await request.post(baseUrl + '/auth', {
- headers: {
- 'Content-Type': 'application/json'
- },
- body: JSON.stringify({
- username: username,
- password: password
- })
- });
- return JSON.parse(response).authenticationToken;
- }
Add Comment
Please, Sign In to add comment