{"_id":"@0xtender/gqlg-generator","_rev":"1-72f5ce55b35dcdba66159577c9017e54","name":"@0xtender/gqlg-generator","dist-tags":{"latest":"0.0.1"},"versions":{"0.0.1":{"name":"@0xtender/gqlg-generator","version":"0.0.1","keywords":["graphql","query","generator"],"author":{"name":"0xTender"},"license":"MIT","_id":"@0xtender/gqlg-generator@0.0.1","maintainers":[{"name":"abhinavrobinson","email":"abhinavrobinson@gmail.com"},{"name":"aniketbiprojit","email":"aniket_chowdhury@hotmail.com"}],"homepage":"https://github.com/0xTender/gql-generator#readme","bugs":{"url":"https://github.com/0xTender/gql-generator/issues"},"bin":{"gqlg":"index.js"},"dist":{"shasum":"10951ea7c4e9d2afc0f4a89a59fe1270e488a065","tarball":"https://registry.npmjs.org/@0xtender/gqlg-generator/-/gqlg-generator-0.0.1.tgz","fileCount":11,"integrity":"sha512-HxcHixeoGll3GDt1JE+xyuFmrnVU8xRHIfbpYkSJ0Ylt98kV4wBDtTpPCwpOmO1NbYJQEyi6S7BWmPN5BTPGBw==","signatures":[{"sig":"MEUCICx7XPSlmNV2uGxOZ0XsDBCb8fTPga8pKRWVHS2EUoFFAiEA972R9tuiKdUj/d4rN/AC/RfjJQWql5LUi7AeWoCihcg=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":24691},"main":"index.js","_from":"file:0xtender-gqlg-generator-0.0.1.tgz","private":false,"scripts":{"lint":"eslint ./index.js","test":"mocha -u qunit"},"_npmUser":{"name":"aniketbiprojit","email":"aniket_chowdhury@hotmail.com"},"_resolved":"/private/var/folders/rc/t4cg6cf56hd3p8gx_d6dt8880000gn/T/35d13af71465f67d407a886d96d4182b/0xtender-gqlg-generator-0.0.1.tgz","_integrity":"sha512-HxcHixeoGll3GDt1JE+xyuFmrnVU8xRHIfbpYkSJ0Ylt98kV4wBDtTpPCwpOmO1NbYJQEyi6S7BWmPN5BTPGBw==","repository":{"url":"git+https://github.com/0xTender/gql-generator.git","type":"git"},"_npmVersion":"9.5.1","description":"Generate queries from graphql schema, used for writing api test.","directories":{},"_nodeVersion":"18.16.0","dependencies":{"del":"^3.0.0","graphql":"^16.3.0","commander":"^2.15.1"},"_hasShrinkwrap":false,"devDependencies":{"mocha":"^10.1.0","eslint":"^8.50.0","should":"^13.2.1","eslint-plugin-import":"^2.14.0","eslint-config-airbnb-base":"^13.1.0"},"_npmOperationalInternal":{"tmp":"tmp/gqlg-generator_0.0.1_1696497838404_0.6791286737352165","host":"s3://npm-registry-packages"}}},"time":{"created":"2023-10-05T09:23:58.335Z","modified":"2024-12-30T05:36:46.040Z","0.0.1":"2023-10-05T09:23:58.574Z"},"bugs":{"url":"https://github.com/0xTender/gql-generator/issues"},"author":{"name":"0xTender"},"license":"MIT","homepage":"https://github.com/0xTender/gql-generator#readme","keywords":["graphql","query","generator"],"repository":{"url":"git+https://github.com/0xTender/gql-generator.git","type":"git"},"description":"Generate queries from graphql schema, used for writing api test.","maintainers":[{"email":"aniket_chowdhury@hotmail.com","name":"aniketbiprojit"}],"readme":"# gql-generator\n\nGenerate queries from graphql schema, used for writing api test.\n\n## Example\n\n```gql\n# Sample schema\ntype Query {\n  user(id: Int!): User!\n}\n\ntype User {\n  id: Int!\n  username: String!\n  email: String!\n  createdAt: String!\n}\n```\n\n```gql\n# Sample query generated\nquery user($id: Int!) {\n  user(id: $id) {\n    id\n    username\n    email\n    createdAt\n  }\n}\n```\n\n## Usage\n\n```bash\n# Install\nnpm install gql-generator -g\n\n# see the usage\ngqlg --help\n\n# Generate sample queries from schema file\ngqlg --schemaFilePath ./example/sampleTypeDef.graphql --destDirPath ./example/output --depthLimit 5\n```\n\nNow the queries generated from the [`sampleTypeDef.graphql`](./example/sampleTypeDef.graphql) can be found in the destDir: [`./example/output`](./example/output).\n\nThis tool generate 3 folders holding the queries: mutations, queries and subscriptions. And also `index.js` files to export the queries in each folder.\n\nYou can require the queries like this:\n\n```js\n// require all the queries\nconst queries = require('./example/output');\n// require mutations only\nconst mutations = require('./example/output/mutations');\n\n// sample content\nconsole.log(queries.mutations.signup);\nconsole.log(mutations.signup);\n/*\nmutation signup($username: String!, email: String!, password: String!){\n  signup(username: $username, email: $email, password: $password){\n    token\n    user {\n      id\n      username\n      email\n      createdAt\n    }\n  }\n}\n*/\n```\n\nThe tool will automatically exclude any `@deprecated` schema fields (see more on schema directives [here](https://www.apollographql.com/docs/graphql-tools/schema-directives)). To change this behavior to include deprecated fields you can use the `includeDeprecatedFields` flag when running the tool, e.g. `gqlg --includeDeprecatedFields`.\n\n### Programmatic Access\n\nAlternatively, you can run `gql-generator` directly from your scripts:\n\n```js\nconst gqlg = require('gql-generator');\n\ngqlg({ schemaFilePath: './example/sampleTypeDef.graphql', destDirPath: './example/output', depthLimit: 5 });\n```\n\n## Usage example\n\nSay you have a graphql schema like this:\n\n```gql\ntype Mutation {\n  signup(email: String!, username: String!, password: String!): UserToken!\n}\n\ntype UserToken {\n  token: String!\n  user: User!\n}\n\ntype User {\n  id: Int!\n  username: String!\n  email: String!\n  createdAt: String!\n}\n```\n\nBefore this tool, you write graphql api test like this:\n\n```js\nconst { GraphQLClient } = require('graphql-request');\nrequire('should');\n\nconst host = 'http://localhost:8080/graphql';\n\ntest('signup', async () => {\n  const gql = new GraphQLClient(host);\n  const query = `mutation signup($username: String!, email: String!, password: String!){\n    signup(username: $username, email: $email, password: $password){\n      token\n      user {\n        id\n        username\n        email\n        createdAt\n      }\n    }\n  }`;\n\n  const data = await gql.request(query, {\n    username: 'tim',\n    email: 'timqian92@qq.com',\n    password: 'samplepass',\n  });\n\n  (typeof data.signup.token).should.equal('string');\n);\n```\n\nAs `gqlg` generated the queries for you, you don't need to write the query yourself, so your test will becomes:\n\n```js\nconst { GraphQLClient } = require('graphql-request');\nrequire('should');\nconst mutations = require('./example/output/mutations');\n\nconst host = 'http://localhost:8080/graphql';\n\ntest('signup', async () => {\n  const gql = new GraphQLClient(host);\n\n  const data = await gql.request(mutations.signup, {\n    username: 'tim',\n    email: 'timqian92@qq.com',\n    password: 'samplepass',\n  });\n\n  (typeof data.signup.token).should.equal('string');\n);\n```\n\n## Notes\n\n- As this tool is used for tests, it expands all of the fields in a query. There might be recursive fields in the query, so `gqlg` ignores the types which have been added in the parent queries already by default. This can be disabled using the `--includeCrossReferences` argument.\n- Variable names are derived from argument names, so variables generated from multiple occurrences of the same argument name must be deduped. An index is appended to any duplicates e.g. `region(language: $language1)`.\n","readmeFilename":"README.md"}