{"bugs":{"url":"https://github.com/dotansimha/graphql-toolkit/issues"},"dist":{"shasum":"c147c93f33a2726aaeb23be96fa5f8732de1658a","tarball":"https://registry.npmjs.org/graphql-toolkit/-/graphql-toolkit-0.5.17-bccc110.0.tgz","fileCount":258,"integrity":"sha512-GqgoEkeW6ksvyfsBxUnK8TDFkCNQhnIygTkmzDuq6Jnu3xGP/OQUQ2+aHVTyGcdYOCRLVYb8lkYkBMs1au7d/Q==","signatures":[{"sig":"MEYCIQCIF/Ow/9FvXGN6lCK1jsgc9WC8SIIiRw240+vZ9/L2KgIhAJsmpp1ba3rZQt5wE5GzmQLEKZnDatPXQK1Gbxyg58Jq","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":412159,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJdoujuCRA9TVsSAnZWagAAo48P/3iiT+VE//P3XFN9QlcC\nD9DbHh52WkVzBdYnCa6TtaclAEoNUdrvtG07pMxj5KonwYkKV4c8RpDaCQ2T\n+agvtfi2W+S0qAj1o2A8rWeQMzZ0bvt0T11iDRzy7TvlzMloL6V1WuExut0A\nNp93ceZtWxAl0YrmtZJvorA6p5CrgOuLk0iOWYV03hCbGJZNd6FMA/5pxfXC\n1+nNM4pz2ipq2x9nTjojapbfgPcop4UDUHfdJcNS4XJtQW2kZsGjCqr8VNk2\nhHYjVqn0gdCdSitPlv8VFr/U+rdJCakqF8usr5JaUg9eJxEbDW0QhFFIuHk6\nRrzSIrnVTulZ8/ypqYUgcsMCun9Xa6C+xY+JdHQ6sYZSJS6zQfHzWjWSx6Op\nkYF+N3Lg7S+Kjy3vVIMPAe23ZW70Sb8s/G6Hh3hR/jI4KaTPmQ2tpxtv1p2F\nWG+2JiL0bJblXAnCheYim3l4WxQFT47tczG3CqtCrM81LfAdfuGdQpb3vHaZ\n4oLWXlSyTsXjfe/To+5E6bWkjervLZWru4yqxK+FrTcCqrZN3V47Ss7mzdhd\nhHuuXazFLkrZ/3CETFcbqJEpj14wYVh4upt22k8WC1Rr4zMGGQ0qRJwupcKd\nfivdWtHFSB3txAqYFIJvvMFeTyiZj5b6b4lCfM3bT7Buc3Ly0Pi2GNSnMVRr\nadPV\r\n=OnjL\r\n-----END PGP SIGNATURE-----\r\n"},"main":"dist/commonjs/index.js","name":"graphql-toolkit","author":{"name":"Dotan Simha","email":"dotansimha@gmail.com"},"module":"dist/esnext/index.js","readme":"![tool](https://user-images.githubusercontent.com/25294569/64810060-4d9c8680-d5a3-11e9-9a66-84ff20e1179f.gif)\n\n[![Discord Chat](https://img.shields.io/discord/625400653321076807)](https://discord.gg/xud7bH9)\n\nA set of utils for faster development of GraphQL tools. Use these utils if you are creating a tool that loads schema/documents, merges schemas, scan for schema/documents/resolvers files.\n\nIncluded tools:\n\n### Schema Loading\n\nThese utils are useful for scanning, loading and building a GraphQL schema from any input.\n\nYou can either specify a GraphQL endpoint, local introspection JSON file, code file that `export`s a GraphQLSchema, AST string and `.graphql` files (with support for `glob` expression).\n\nIt also merges all found schema files into a complete schema, and has support for `#import` syntax (using [`graphql-import`](https://github.com/prisma/graphql-import)).\n\nYou can also extend the loads by implementing you own loader (implement the interface `SchemaLoader`).\n\nThe schema loading util is using loaders, and implemented using [chain-of-responsibility pattern](https://en.wikipedia.org/wiki/Chain-of-responsibility_pattern). \n\nYou don't have to specify which loader to use - just provide your input and this utils will detect it automatically.\n\nUsage:\n\n```ts\nimport { loadSchema } from 'graphql-toolkit';\n\nconst schema1 = loadSchema('type A { foo: String }'); // load from string\nconst schema2 = loadSchema('http://localhost:3000/graphql'); // load from endpoint\nconst schema3 = loadSchema('./schema.json'); // load from local json file\nconst schema4 = loadSchema('schema.graphql'); // load from a single schema file\nconst schema5 = loadSchema('./src/**/*.graphql'); // load from multiple files using glob\n```\n\n### Documents Loading\n\nSimilar to schema loading - but meant to use for GraphQL documents (query/mutation/subscription/fragment).\n\nYou an specify any input as source, and this utils will detect it automatically. \n\nIt also extracts usages of `gql` from code files using [`graphql-tag-pluck`](https://github.com/DAB0mB/graphql-tag-pluck).\n\nUsage:\n\n```ts\nimport { loadDocuments } from 'graphql-toolkit';\n\nconst document1 = loadDocuments('query { f }'); // load from string\nconst document2 = loadDocuments('./users.query.graphql'); // load from a single file \nconst document3 = loadDocuments('./src/**/*.graphql'); // load from multiple files using glob\nconst document4 = loadDocuments('./src/my-component.ts'); // load from code file\n```\n\n### Epoxy\n\nOriginally implemented in [graphql-modules](https://github.com/Urigo/graphql-modules). This tools merged GraphQL type definitions and schema. It aims to merge all possible types, interfaces, enums and unions, without conflicts.\n\nIt also merged resolvers by using deep-merge, so you can separate your resolvers implementating across multiple objects and the merge it into a single `resolvers` object.\n\n```graphql\n# a1.graphql\ntype A {\n    f1: String\n}\n\n# a2.graphql\ntype A {\n    f2: String\n}\n```\n\nWill result:\n```graphql\ntype A {\n    f1: String\n    f2: String\n}\n```\n\n### Sonar\n\nSonar is a small util that scans you file-system and find GraphQL files (`.graphql`) and resolvers files (`.js`/`.ts`) and loads them (using `readFile` for GraphQL files and `require` for resolvers files).\n\n### Other Utils\n\nThere are some more utils under `utils` directory:\n\n#### `validateGraphQlDocuments`\n\nA tool for validating GraphQL documents (query/mutation/subscription/fragment) against the schema.\n\nIt uses the original validation logic from `graphql` package, but suspressing some validation rules, and focuses on validating the fields and the structure of the documents.\n\n#### `extractDocumentStringFromCodeFile`\n\nThis method gets a source code file, and using `graphql-tag-pluck` tries to extract GraphQL AST from it. \n\n#### `getDirectives`\n\nThis method accepts `GraphQLSchema` and any AST node, and tries to extract the GraphQL directives of the AST node. \n\nIt returnes a `Map` of the directive name and the arguments of it. \n\n#### `getFieldsWithDirectives`\n\nThis method accepts a GraphQL `DocumentNode` of a GraphQL types definition and creates a map between GraphQL `type.field` and the directives it has. \n\nIt's useful for getting an easy-to-use structure of the directives that are decorating the schema. \n\n#### `getImplementingTypes`\n\nThis method accepts `GraphQLSchema` object and a name of a GraphQL interface, and returns an array of all the GraphQL types that are implementing the GraphQL `interface`.\n\n#### `getSchemaDirectiveFromDirectiveResolver`\n\nThis method accepts a name of a GraphQL Directive and its resolver function; using this method you can easily generate `SchemaDirective` with a single resolver function.\n\n#### `composeResolvers`\n\nThis method accepts `IResolvers` object and mappings for composition functions that would be run before resolver itself.\n\nInstead of doing this,\n\n```js\nconst resolvers ={\n    Query: {\n        myQuery: (root, args, context) => {\n            // Make sure that the user is authenticated\n            if (!context.currentUser) {\n                throw new Error('You are not authenticated!');\n            }\n\n            // Make sure that the user has the correct roles\n            if (!context.currentUser.roles || context.currentUser.roles.includes('EDITOR')) {\n                throw new Error('You are not authorized!');\n            }\n\n            // Business logic\n            if (args.something === '1') {\n                return true;\n            }\n\n            return false;\n        },\n    },\n};\n```\n\nYou can do;\n\n```js\nconst resolvers ={\n    Query: {\n        myQuery: (root, args, context) => {\n            if (args.something === '1') {\n                return true;\n            }\n\n            return false;\n        },\n    },\n};\n\nconst isAuthenticated = () => next => async (root, args, context, info) => {\n    if (!context.currentUser) {\n        throw new Error('You are not authenticated!');\n    }\n\n    return next(root, args, context, info);\n};\n\nconst hasRole = (role: string) => next => async (root, args, context, info) => {\n    if (!context.currentUser.roles || context.currentUser.roles.includes(role)) {\n        throw new Error('You are not authorized!');\n    }\n\n    return next(root, args, context, info);\n};\n\nconst resolversComposition = {\n    'Query.myQuery': [isAuthenticated(), hasRole('EDITOR')],\n};\n\nconst composedResolvers = composeResolvers(resolvers, resolversComposition);\n```\n\n#### `extractResolversFromSchema`\n\nThis methods accepts `GraphQLSchema` object, and returns a map with field resolver functions of all types inside the schema as in [`IResolvers` interface of `graphql-tools`.](https://www.apollographql.com/docs/graphql-tools/resolvers.html)\n\n#### `extractFieldResolversFromObjectType`\n\nThis methods accepts `GraphQLObjectType` or `GraphQLInterfaceType` object, and returns a map with field resolvers of given type.\n","gitHead":"bccc110c2ae24ee913e52535f632818e687920e0","license":"MIT","scripts":{"test":"jest --forceExit && yarn bundlesize","build":"tsc -m esnext --outDir dist/esnext && tsc -m commonjs --outDir dist/commonjs","clean":"rimraf dist","release":"yarn prepare-release && npm publish","bundlesize":"cd bundle-test/ && yarn && yarn test","prepare-release":"yarn build && yarn test","ci:release:canary":"node bump.js && npm publish --tag alpha"},"typings":"dist/esnext/index.d.ts","_npmUser":{"name":"dotansimha","email":"dotansimha@gmail.com"},"homepage":"https://github.com/dotansimha/graphql-toolkit#readme","repository":{"url":"git+ssh://git@github.com/dotansimha/graphql-toolkit.git","type":"git"},"typescript":{"definition":"dist/esnext/index.d.ts"},"_npmVersion":"6.11.3","description":"A set of utils for faster development of GraphQL tools","directories":{},"maintainers":[{"name":"dotansimha","email":"dotansimha@gmail.com"}],"sideEffects":false,"_nodeVersion":"12.11.1","dependencies":{"tslib":"^1.9.3","globby":"10.0.1","lodash":"4.17.15","asyncro":"^3.0.0","is-glob":"4.0.1","deepmerge":"4.1.1","valid-url":"1.0.9","@types/glob":"7.1.1","cross-fetch":"^3.0.4","is-valid-path":"0.1.1","graphql-import":"0.7.1","aggregate-error":"3.0.1","@kamilkisiela/graphql-tools":"4.0.6"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"jest":"24.9.0","rimraf":"3.0.0","semver":"6.3.0","graphql":"14.5.8","ts-jest":"24.1.0","jest-junit":"8.0.0","typescript":"3.6.4","@types/jest":"24.0.18","@types/node":"10.14.21","graphql-tag":"2.10.1","@types/lodash":"4.14.144","@types/is-glob":"4.0.1","@types/request":"2.48.3","@types/deepmerge":"2.2.0","@types/valid-url":"1.0.2","graphql-tag-pluck":"0.8.5","graphql-type-json":"0.3.0"},"peerDependencies":{"graphql":"^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0","graphql-tag-pluck":"^0.8.3"},"_npmOperationalInternal":{"tmp":"tmp/graphql-toolkit_0.5.17-bccc110.0_1570957549121_0.9415090737702614","host":"s3://npm-registry-packages"},"_id":"graphql-toolkit@0.5.17-bccc110.0","version":"0.5.17-bccc110.0"}