UNPKG

graphql-query-gen

Version:

Node.js module to generate queries with random input data from graphQL endpoint or schema

110 lines (96 loc) 1.95 kB
const graphqlQueryGen = require('./index'); const options = { debug: false, responseDepth: 5, inputDepth: 7, indentBy: 2, spacer: ' ', filter: null, inputVariables: true, duplicatePercentage: 75, headers: {"Authorization": "Bearer eydfdgfgFGFGFG33"}, operationName: true, comments: true, }; // Process using endpoint try { process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = 0 graphqlQueryGen.processEndpoint( "https://rickandmortyapi.com/graphql", options ).then( result => console.log(result) ).catch( error => console.log(error.message) ) } catch (err) { console.log(err.message); } // Process using schema const s = ` type Character { id: ID name: [String]! sex: Gender } type Jedi { id: ID side: String! } type Droid { id: ID model: Model } type Model { key: String } input Char { id: ID name: [String]! } input Char2 { id: ID name: [String]! } input TestInput { key1: String key2: [Int!]! key3: Float! key4: Char key5: Gender } enum Gender { MALE FEMALE OTHER } union People = Character | Jedi | Droid type Query { """ This is a comment for allPeople Query """ allPeople( """ First Input """ input: TestInput!, input2: [String]!): [People] testScalar(a: String): JSON } scalar JSON `; try { const result = graphqlQueryGen.processSchema(s, options); console.log(JSON.stringify(result, undefined, 4)); } catch (err) { console.log('Error: ' + err.message); } // Process using SDL const fs = require('fs'); let rawdata = fs.readFileSync('sdl.json'); const sdl = JSON.parse(rawdata); try { const result = graphqlQueryGen.processSDL(sdl.data, options); console.log(result.schema, { 'maxArrayLength': null }); } catch (err) { console.log('Error: ' + err.message); }