{"_id":"@brysgo/graphql-anywhere","_rev":"2-4e679bf80aff822000ef2a5f5b806f9d","name":"@brysgo/graphql-anywhere","dist-tags":{"latest":"3.1.0"},"versions":{"0.0.0-semantic-release":{"name":"@brysgo/graphql-anywhere","private":false,"version":"0.0.0-semantic-release","description":"Run GraphQL queries with no schema and just one resolver","main":"./lib/src/index.js","typings":"./lib/src/index.d.ts","scripts":{"pretest":"npm run compile","test":"npm run testonly --","posttest":"npm run lint","compile":"tsc","watch":"tsc -w","prepublish":"npm run compile","lint":"grunt tslint","coverage":"istanbul cover ./node_modules/mocha/bin/_mocha -- --reporter dot --full-trace lib/test/tests.js","postcoverage":"remap-istanbul --input coverage/coverage.json --type lcovonly --output coverage/lcov.info","testonly":"mocha --reporter spec --full-trace lib/test/tests.js"},"repository":{"type":"git","url":"git+https://github.com/brysgo-forks/graphql-anywhere.git"},"keywords":["ecmascript","es2015","jsnext","javascript","relay","npm","react"],"author":{"name":"Sashko Stubailo","email":"sashko@stubailo.com"},"license":"MIT","devDependencies":{"@types/chai":"3.5.2","@types/isomorphic-fetch":"0.0.34","@types/graphql":"^0.10.0","@types/lodash":"^4.14.37","@types/mocha":"^2.2.32","@types/node":"^8.0.0","@types/react":"^15.0.14","@types/react-dom":"^15.5.0","async":"^2.0.0","chai":"^4.1.0","chai-as-promised":"^7.0.0","es6-promise":"^4.0.5","graphql":"^0.10.0","graphql-tag":"^2.0.0","grunt":"1.0.1","grunt-tslint":"5.0.0","isomorphic-fetch":"^2.2.1","istanbul":"^0.4.5","mocha":"^3.0.0","react":"^15.3.1","react-dom":"^15.3.1","remap-istanbul":"^0.8.0","source-map-support":"^0.4.0","tslint":"^5.0.0","typescript":"^2.2.1"},"gitHead":"834efe2f71ac2afd9b4a80679056c087d05f8c3c","bugs":{"url":"https://github.com/brysgo-forks/graphql-anywhere/issues"},"homepage":"https://github.com/brysgo-forks/graphql-anywhere#readme","_id":"@brysgo/graphql-anywhere@0.0.0-semantic-release","_nodeVersion":"11.9.0","_npmVersion":"6.8.0","dist":{"integrity":"sha512-AH6eb1ptkeJrXoBdyW7G00wUoOav/Nd4OytjWSkPx405qCWjTM0M7m7kBSU3iXGKm6JJKC++Pa791jidtyJvQA==","shasum":"288706576fbb2763ca25eadfe7f7ee72680114f2","tarball":"https://registry.npmjs.org/@brysgo/graphql-anywhere/-/graphql-anywhere-0.0.0-semantic-release.tgz","fileCount":32,"unpackedSize":75425,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJcccCkCRA9TVsSAnZWagAApYsP/3F+kyDH1budY3xfXCLb\nnoGKozLzTg7tbqxfDJvcwL1d9v7JMbaOkp3UgDv7jjYIzUYmrUj9U8pE6MjO\nHDCPJc5i2XQDyoLN7thWn8MC92iHUS7IZz4Pw2yW4qsAKXyr4wM6QnPgQOxq\nTcC2xGmJwVP2536As0/cM1xMwoJfGxur5PfvSrnHy+MSv4cAr7T1gSs1hkjL\n15ZPn5gUaHWnKg2sXt7BJCIXNUvB5IVGvHqGvaZdnULoereGrlYmffuddoyj\nRqUI10pWMBjc2//V0lf7BuunHqdmXwQ+8nYhkHUSfiLMJvvR46K25MD/dS+c\nCv7HB6BICHVDATXGhoNL8PBoY4LBJHGOd+Cxy1glhWzuaeqZsjdktxh6IQ9F\nj6T4CL6feIQ6yICVRweZJ/2YFp5avq9oJwnm4PdZJ/OMeBkOTpVs9dooJthC\nmKiJDa/TS7LvdJMdx6iS4aVP6GpjmmZ3v4qRCNw37F98tcIDSpvuuWEoaFb+\nHf/R70I+9UqC8cg52zVZVejYKiZMmGK+rXGPnYJLzaAnaSu65bMvfQ4WwuC/\n4Mf1073ld88FK19QM+hGH326ZKTUTXeHOduur+Jq83tywbsXu/SjsXrB5Kmb\nVbvOQf/A9b9P9Awh201QDajW+1aNvpT+SOVNcRrKcSN+159NlsGl1YGTniiE\ndvte\r\n=/I6w\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIDPTK+dkEvDM2zt7pXTj3igBNQfoCklJykAKnjKuPLRbAiEAs7AkfZ6eUQ6JPE3pXli2Jc5C/vn2i6abzGWcQZo7H0g="}]},"maintainers":[{"name":"brysgo1","email":"brysgo@gmail.com"}],"_npmUser":{"name":"brysgo1","email":"brysgo@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/graphql-anywhere_0.0.0-semantic-release_1550958755860_0.5392944712151744"},"_hasShrinkwrap":false},"3.1.0":{"name":"@brysgo/graphql-anywhere","private":false,"version":"3.1.0","description":"Run GraphQL queries with no schema and just one resolver","main":"./lib/src/index.js","typings":"./lib/src/index.d.ts","scripts":{"pretest":"npm run compile","test":"npm run testonly --","posttest":"npm run lint","compile":"tsc","watch":"tsc -w","prepublish":"npm run compile","lint":"grunt tslint","coverage":"istanbul cover ./node_modules/mocha/bin/_mocha -- --reporter dot --full-trace lib/test/tests.js","postcoverage":"remap-istanbul --input coverage/coverage.json --type lcovonly --output coverage/lcov.info","testonly":"mocha --reporter spec --full-trace lib/test/tests.js"},"repository":{"type":"git","url":"https://github.com/brysgo-forks/graphql-anywhere.git"},"keywords":["ecmascript","es2015","jsnext","javascript","relay","npm","react"],"author":{"name":"Sashko Stubailo","email":"sashko@stubailo.com"},"license":"MIT","devDependencies":{"@types/chai":"3.5.2","@types/isomorphic-fetch":"0.0.34","@types/graphql":"^0.10.0","@types/lodash":"^4.14.37","@types/mocha":"^2.2.32","@types/node":"^8.0.0","@types/react":"^15.0.14","@types/react-dom":"^15.5.0","async":"^2.0.0","chai":"^4.1.0","chai-as-promised":"^7.0.0","es6-promise":"^4.0.5","graphql":"^0.10.0","graphql-tag":"^2.0.0","grunt":"1.0.1","grunt-tslint":"5.0.0","isomorphic-fetch":"^2.2.1","istanbul":"^0.4.5","mocha":"^3.0.0","react":"^15.3.1","react-dom":"^15.3.1","remap-istanbul":"^0.8.0","source-map-support":"^0.4.0","tslint":"^5.0.0","typescript":"^2.2.1"},"licenseText":"The MIT License (MIT)\n\nCopyright (c) 2015 - 2016 Oleksandr Stubailo\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n\n","_id":"@brysgo/graphql-anywhere@3.1.0","dist":{"shasum":"799974e0d3d40c935843e82d7bfee09ad775aa6a","integrity":"sha512-HJV68Mmk26U4lgE/swDa7Ur+JWU5O6Pcuoa8BRjq/0f1PITWlN56VVZAA7cfFfHiFWrrziiCFe53ZIaU8s+zMg==","tarball":"https://registry.npmjs.org/@brysgo/graphql-anywhere/-/graphql-anywhere-3.1.0.tgz","fileCount":38,"unpackedSize":146471,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJcccERCRA9TVsSAnZWagAA3GcP/iSfxR8ECTJ2RT2RzUmd\nVg6jexbTXOe4PRUnxLLucxVKazPloZ/kWMNaAA+hZPIKgJvmDG6TlvRzmdSk\nh/qmEdf7JUbgiNezY6lRQWPR0S/r5rMw6owx2A8oTGP7Iuil3NOx1VmeThqr\nlDZp54pO/Op5HxjWCTrojn0TyxKaJm0GXwz1VraeLM6j2etaZ6V1H28waUfS\nnhiCT6/xyJpOh4VdBwBPMGZ084h5uOHdONiunIxIij/jdatOVxMZByqw1418\nui0s/JcZmiFc/pTmfOAkSu1EQfBHr9JfwASGYmaKxwrFbOf/qJ3OOlIECUSs\nQ/Ihiq84gFBovjJiJXXj/WJ5iDxBvSTb40Kg+uSKV5SNOpIAfU8PYAuNRnC/\nwz9NnfP3I5uNdGF4+HisB8qP4ft8H0Sa6/Cpx14TC0SMV8s3rqrWuZubx8G2\nGOuT7tSlI0i854d4YVQgX+n3V4ciHWEVcZbV4GYnWWGC0p7Gp6V0EkcCYEDH\nIpGtaU4+pjo3yxYJocCT5pXrK4AkU5rF/YCiChiaiVRPxPhx3KP4D34rIaGM\nPkIFP9JiyeG0CRa6ez7ciExaWznjXIgjJJN6p5ivYLC+Hic5RWPB6tNmQAcw\nUjeaX6JVS+8coGmKprwBEd0xB/WJwLfozQVxAtFUbbC86L/EY+m5xBT3nAff\nkBLQ\r\n=MH8w\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIET0z8HA9cRgr4B3Kv+DMrB74RmDUEbGYL7lD+IlzeBtAiBV5WoYj5DKH3Ew2ID3w6VTzhvFhrok5Ptk84c0c2Hzww=="}]},"maintainers":[{"name":"brysgo1","email":"brysgo@gmail.com"}],"_npmUser":{"name":"brysgo1","email":"brysgo@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/graphql-anywhere_3.1.0_1550958864339_0.9640219821018898"},"_hasShrinkwrap":false}},"time":{"created":"2019-02-23T21:52:35.719Z","0.0.0-semantic-release":"2019-02-23T21:52:36.139Z","modified":"2022-04-04T20:50:18.702Z","3.1.0":"2019-02-23T21:54:24.492Z"},"maintainers":[{"name":"brysgo1","email":"brysgo@gmail.com"}],"description":"Run GraphQL queries with no schema and just one resolver","keywords":["ecmascript","es2015","jsnext","javascript","relay","npm","react"],"repository":{"type":"git","url":"https://github.com/brysgo-forks/graphql-anywhere.git"},"author":{"name":"Sashko Stubailo","email":"sashko@stubailo.com"},"license":"MIT","readme":"# graphql-anywhere\n\n[![npm version](https://badge.fury.io/js/graphql-anywhere.svg)](https://badge.fury.io/js/graphql-anywhere)\n[![Build Status](https://travis-ci.org/apollographql/graphql-anywhere.svg?branch=master)](https://travis-ci.org/apollostack/graphql-anywhere)\n\nRun a GraphQL query anywhere, without a GraphQL server or a schema. Just pass in one resolver. Use it together with [graphql-tag](https://github.com/apollographql/graphql-tag).\n\n```\nnpm install graphql-anywhere graphql-tag\n```\n\nI think there are a lot of potentially exciting use cases for a completely standalone and schema-less GraphQL execution engine. We use it in [Apollo Client](https://github.com/apollostack/apollo-client) to read data from a Redux store with GraphQL.\n\nLet's come up with some more ideas - below are some use cases to get you started!\n\n## API\n\n```js\nimport graphql from 'graphql-anywhere'\n\ngraphql(resolver, document, rootValue?, context?, variables?, options?)\n```\n\n- `resolver`: A single resolver, called for every field on the query.\n    - Signature is: `(fieldName, rootValue, args, context, info) => any`\n- `document`: A GraphQL document, as generated by the template literal from `graphql-tag`\n- `rootValue`: The root value passed to the resolver when executing the root fields\n- `context`: A context object passed to the resolver for every field\n- `variables`: A dictionary of variables for the query\n- `options`: Options for execution\n\n#### Options\n\nThe last argument to the `graphql` function is a set of `graphql-anywhere`-specific options.\n\n- `resultMapper`: Transform field results after execution.\n    - Signature is: `(resultFields, resultRoot) => any`\n- `fragmentMatcher`: Decide whether to execute a fragment. Default is to always execute all fragments.\n    - Signature is: `(rootValue, typeCondition, context) => boolean`\n\n#### Resolver info\n\n`info`, the 5th argument to the resolver, is an object with supplementary information about execution. Send a PR or open an issue if you need additional information here.\n\n- `isLeaf`: A boolean that is `true` if this resolver is for a leaf field of the query, i.e. one that doesn't have a sub-selection.\n- `resultKey`: The key the result of this field will be put under. It's either the field name from the query, or the field alias.\n- `directives`: An object with information about all directives on this field. It's an object of the format `{ [directiveName]: { [argumentName]: value }}`. So for example a field with `@myDirective(hello: \"world\")` will be passed as `{ myDirective: { hello: 'world' }}`. Note that fields can't have multiple directives with the same name, as written in the GraphQL spec.\n\n\n## Utilities\n\nSee http://dev.apollodata.com/react/fragments.html for examples of how you might use these.\n\n```js\nimport { filter } from 'graphql-anywhere'\n\nfilter(doc, data);\n```\n\n- `doc`: a GraphQL document, as generated by the template literal from `graphql-tag`, typically either a query or a fragment.\n- `data`: an object of data to be filtered by the `doc`\n\nFilter `data` according to `doc`.\n\n\n```js\nimport { check } from 'graphql-anywhere'\n\ncheck(doc, data);\n```\n\n- `doc`: a GraphQL document, as generated by the template literal from `graphql-tag`, typically either a query or a fragment.\n- `data`: an object of data, as may have been filtered by `doc`.\n\nCheck that `data` is of the form defined by the query or fragment. Throw an exception if not.\n\n```js\nimport { propType } from 'graphql-anywhere'\n\nX.propTypes = {\n  foo: propType(doc),\n  bar: propType(doc).isRequired,\n}\n\n```\n\n- `doc`: a GraphQL document, as generated by the template literal from `graphql-tag`, typically either a query or a fragment.\n\nGenerate a React `propType` checking function to ensure that the passed prop is in the right form.\n\n### Supported GraphQL features\n\nWhy do you even need a library for this? Well, running a GraphQL query isn't as simple as just traversing the AST, since there are some pretty neat features that make the language a bit more complex to execute.\n\n- [x] Arguments\n- [x] Variables\n- [x] Aliases\n- [x] Fragments, both named and inline\n- [x] `@skip` and `@include` directives\n\nIf you come across a GraphQL feature not supported here, please file an issue.\n\n<a id=\"filter\"></a>\n## Example: Filter a nested object\n\n```js\nimport gql from 'graphql-tag';\nimport graphql from 'graphql-anywhere';\n\n// I don't need all this stuff!\nconst gitHubAPIResponse = {\n  \"url\": \"https://api.github.com/repos/octocat/Hello-World/issues/1347\",\n  \"title\": \"Found a bug\",\n  \"body\": \"I'm having a problem with this.\",\n  \"user\": {\n    \"login\": \"octocat\",\n    \"avatar_url\": \"https://github.com/images/error/octocat_happy.gif\",\n    \"url\": \"https://api.github.com/users/octocat\",\n  },\n  \"labels\": [\n    {\n      \"url\": \"https://api.github.com/repos/octocat/Hello-World/labels/bug\",\n      \"name\": \"bug\",\n      \"color\": \"f29513\"\n    }\n  ],\n};\n\n// Write a query that gets just the fields we want\nconst query = gql`\n  {\n    title\n    user {\n      login\n    }\n    labels {\n      name\n    }\n  }\n`;\n\n// Define a resolver that just returns a property\nconst resolver = (fieldName, root) => root[fieldName];\n\n// Filter the data!\nconst result = graphql(\n  resolver,\n  query,\n  gitHubAPIResponse\n);\n\nassert.deepEqual(result, {\n  \"title\": \"Found a bug\",\n  \"user\": {\n    \"login\": \"octocat\",\n  },\n  \"labels\": [\n    {\n      \"name\": \"bug\",\n    }\n  ],\n});\n```\n\n<a id=\"mock\"></a>\n## Example: Generate mock data\n\n```js\n// Write a query where the fields are types, but we alias them\nconst query = gql`\n  {\n    author {\n      name: string\n      age: int\n      address {\n        state: string\n      }\n    }\n  }\n`;\n\n// Define a resolver that uses the field name to determine the type\n// Note that we get the actual name, not the alias, but the alias\n// is used to determine the location in the response\nconst resolver = (fieldName) => ({\n  string: 'This is a string',\n  int: 5,\n}[fieldName] || 'continue');\n\n// Generate the object!\nconst result = graphql(\n  resolver,\n  query\n);\n\nassert.deepEqual(result, {\n  author: {\n    name: 'This is a string',\n    age: 5,\n    address: {\n      state: 'This is a string',\n    },\n  },\n});\n```\n<a id=\"normalizr\"></a>\n## Example: Read from a Redux store generated with Normalizr\n\n```js\nconst data = {\n  result: [1, 2],\n  entities: {\n    articles: {\n      1: { id: 1, title: 'Some Article', author: 1 },\n      2: { id: 2, title: 'Other Article', author: 1 },\n    },\n    users: {\n      1: { id: 1, name: 'Dan' },\n    },\n  },\n};\n\nconst query = gql`\n  {\n    result {\n      title\n      author {\n        name\n      }\n    }\n  }\n`;\n\nconst schema = {\n  articles: {\n    author: 'users',\n  },\n};\n\n// This resolver is a bit more complex than others, since it has to\n// correctly handle the root object, values by ID, and scalar leafs.\nconst resolver = (fieldName, rootValue, args, context): any => {\n  if (!rootValue) {\n    return context.result.map((id) => assign({}, context.entities.articles[id], {\n      __typename: 'articles',\n    }));\n  }\n\n  const typename = rootValue.__typename;\n  // If this field is a reference according to the schema\n  if (typename && schema[typename] && schema[typename][fieldName]) {\n    // Get the target type, and get it from entities by ID\n    const targetType: string = schema[typename][fieldName];\n    return assign({}, context.entities[targetType][rootValue[fieldName]], {\n      __typename: targetType,\n    });\n  }\n\n  // This field is just a scalar\n  return rootValue[fieldName];\n};\n\nconst result = graphql(\n  resolver,\n  query,\n  null,\n  data // pass data as context since we have to access it all the time\n);\n\n// This is the non-normalized data, with only the fields we asked for in our query!\nassert.deepEqual(result, {\n  result: [\n    {\n      title: 'Some Article',\n      author: {\n        name: 'Dan',\n      },\n    },\n    {\n      title: 'Other Article',\n      author: {\n        name: 'Dan',\n      },\n    },\n  ],\n});\n```\n\n## Example: Generate React components\n\nYou can use the `resultMapper` option to convert your results into anything you like. In this case, we convert the result fields into children for a React component:\n\n```js\nconst resolver = (fieldName, root, args) => {\n  if (fieldName === 'text') {\n    return args.value;\n  }\n\n  return createElement(fieldName, args);\n};\n\nconst reactMapper = (childObj, root) => {\n  const reactChildren = Object.keys(childObj).map(key => childObj[key]);\n\n  if (root) {\n    return cloneElement(root, root.props, ...reactChildren);\n  }\n\n  return reactChildren[0];\n};\n\nfunction gqlToReact(query): any {\n  return graphql(\n    resolver,\n    query,\n    '',\n    null,\n    null,\n    { resultMapper: reactMapper },\n  );\n}\n\nconst query = gql`\n  {\n    div {\n      s1: span(id: \"my-id\") {\n        text(value: \"This is text\")\n      }\n      s2: span\n    }\n  }\n`;\n\nassert.equal(\n  renderToStaticMarkup(gqlToReact(query)),\n  '<div><span id=\"my-id\">This is text</span><span></span></div>'\n);\n```\n","readmeFilename":"README.md"}