Guest User

Untitled

a guest
Jun 27th, 2018
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. #!/usr/bin/env node
  2. const os = require('os');
  3. const request = require('request-promise-native');
  4. const fs = require('mz/fs');
  5.  
  6. let hostname = os.hostname();
  7. let baseUrl = 'YOUR_BASE_URL';
  8.  
  9. (async () => {
  10. let jwt = await getJwt();
  11. console.log("JWT Fetched");
  12. console.log("Getting Schema");
  13.  
  14. let response = await request.post(baseUrl + '/graphql', {
  15. headers: {
  16. 'Content-Type': 'application/json',
  17. 'YOUR_HEADER+NAME': jwt
  18. },
  19. body: JSON.stringify({
  20. query: `
  21. query IntrospectionQuery {
  22. __schema {
  23. queryType { name }
  24. mutationType { name }
  25. subscriptionType { name }
  26. types {
  27. ...FullType
  28. }
  29. directives {
  30. name
  31. description
  32. locations
  33. args {
  34. ...InputValue
  35. }
  36. }
  37. }
  38. }
  39.  
  40. fragment FullType on __Type {
  41. kind
  42. name
  43. description
  44. fields(includeDeprecated: true) {
  45. name
  46. description
  47. args {
  48. ...InputValue
  49. }
  50. type {
  51. ...TypeRef
  52. }
  53. isDeprecated
  54. deprecationReason
  55. }
  56. inputFields {
  57. ...InputValue
  58. }
  59. interfaces {
  60. ...TypeRef
  61. }
  62. enumValues(includeDeprecated: true) {
  63. name
  64. description
  65. isDeprecated
  66. deprecationReason
  67. }
  68. possibleTypes {
  69. ...TypeRef
  70. }
  71. }
  72.  
  73. fragment InputValue on __InputValue {
  74. name
  75. description
  76. type { ...TypeRef }
  77. defaultValue
  78. }
  79.  
  80. fragment TypeRef on __Type {
  81. kind
  82. name
  83. ofType {
  84. kind
  85. name
  86. ofType {
  87. kind
  88. name
  89. ofType {
  90. kind
  91. name
  92. ofType {
  93. kind
  94. name
  95. ofType {
  96. kind
  97. name
  98. ofType {
  99. kind
  100. name
  101. ofType {
  102. kind
  103. name
  104. }
  105. }
  106. }
  107. }
  108. }
  109. }
  110. }
  111. }`
  112. })
  113. });
  114.  
  115. await fs.writeFile('graphql.schema.json', JSON.stringify(JSON.parse(response), null, "\t"));
  116.  
  117. console.log("Schema Updated!");
  118. })();
  119.  
  120.  
  121.  
  122. async function getJwt() {
  123. let username = 'YOUR_USERNAME';
  124. let password = 'YOUR_PASSWPRD';
  125.  
  126. let response = await request.post(baseUrl + '/auth', {
  127. headers: {
  128. 'Content-Type': 'application/json'
  129. },
  130. body: JSON.stringify({
  131. username: username,
  132. password: password
  133. })
  134. });
  135.  
  136. return JSON.parse(response).authenticationToken;
  137. }
Add Comment
Please, Sign In to add comment