{"name":"graphql-compose","version":"3.0.0-beta.3","description":"GraphQL schema builder from different data sources with middleware extensions.","files":["lib"],"main":"lib/index.js","types":"lib/index.d.ts","repository":{"type":"git","url":"git+https://github.com/graphql-compose/graphql-compose.git"},"keywords":["graphql","compose"],"license":"MIT","bugs":{"url":"https://github.com/graphql-compose/graphql-compose/issues"},"homepage":"https://github.com/graphql-compose/graphql-compose","peerDependencies":{"graphql":">=0.9.0 || >=0.10.0 || >=0.11.0 || >=0.13.0"},"devDependencies":{"@types/graphql":"^0.12.3","babel-cli":"^6.26.0","babel-eslint":"^8.2.1","babel-jest":"^22.2.0","babel-plugin-transform-class-properties":"^6.24.1","babel-plugin-transform-flow-strip-types":"^6.22.0","babel-plugin-transform-object-rest-spread":"^6.26.0","babel-plugin-transform-runtime":"^6.23.0","babel-preset-env":"^1.6.1","cz-conventional-changelog":"^2.1.0","eslint":"^4.17.0","eslint-config-airbnb-base":"^12.1.0","eslint-config-prettier":"^2.9.0","eslint-plugin-flowtype":"^2.42.0","eslint-plugin-import":"^2.8.0","eslint-plugin-prettier":"^2.6.0","flow-bin":"^0.65.0","graphql":"0.13.0","jest":"^22.2.1","prettier":"^1.10.2","rimraf":"^2.6.2","semantic-release":"^12.4.1","tslint":"^5.9.1","typescript":"^2.7.1"},"dependencies":{"babel-runtime":"^6.26.0","object-path":"^0.11.4"},"config":{"commitizen":{"path":"./node_modules/cz-conventional-changelog"}},"jest":{"roots":["<rootDir>/src"]},"scripts":{"build":"npm run build-cjs && npm run build-flow && npm run build-ts","build-cjs":"rimraf lib && babel src --ignore __tests__,__mocks__ -d lib","build-flow":"find ./src -name '*.js' -not -path '*/__*' | while read filepath; do cp $filepath `echo $filepath | sed 's/\\/src\\//\\/lib\\//g'`.flow; done","build-ts":"find ./src -name '*.d.ts' -not -path '*/__*' | while read filepath; do cp $filepath `echo $filepath | sed 's/\\/src\\//\\/lib\\//g'`; done","watch":"jest --watch","coverage":"jest --coverage","lint":"npm run eslint && npm run tslint","eslint":"eslint --ext .js ./src","tslint":"tslint -p . \"src/**/*.d.ts\"","tscheck":"tsc","flow":"flow","glow":"glow --watch","test":"npm run coverage && npm run lint && npm run flow && npm run tscheck","link":"yarn link graphql && yarn link","unlink":"yarn unlink graphql && yarn add graphql","semantic-release":"semantic-release","test-vers":"yarn add graphql@0.9.0 && jest && yarn add graphql@0.10.0 && jest && yarn add graphql@0.11.0 && jest && yarn add graphql@0.13.0-rc.1 && jest"},"contributors":[{"name":"Pavel Chertorogov","email":"pavel.chertorogov@gmail.com"}],"readme":"# GraphQL-compose\n\n[![](https://img.shields.io/npm/v/graphql-compose.svg)](https://www.npmjs.com/package/graphql-compose)\n[![codecov coverage](https://img.shields.io/codecov/c/github/graphql-compose/graphql-compose.svg)](https://codecov.io/github/graphql-compose/graphql-compose)\n[![Travis](https://img.shields.io/travis/graphql-compose/graphql-compose.svg?maxAge=2592000)](https://travis-ci.org/graphql-compose/graphql-compose)\n[![npm](https://img.shields.io/npm/dt/graphql-compose.svg)](http://www.npmtrends.com/graphql-compose)\n[![Join the chat at https://gitter.im/graphql-compose/Lobby](https://badges.gitter.im/graphql-compose/graphql-compose.svg)](https://gitter.im/graphql-compose/Lobby)\n[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)\n[![Greenkeeper badge](https://badges.greenkeeper.io/graphql-compose/graphql-compose.svg)](https://greenkeeper.io/)\n![TypeScript compatible](https://img.shields.io/badge/typescript-compatible-brightgreen.svg)\n![FlowType compatible](https://img.shields.io/badge/flowtype-compatible-brightgreen.svg)\n\n[GraphQL](http://graphql.org/) – is a query language for APIs. [graphql-js](https://github.com/graphql/graphql-js) is the reference implementation of GraphQL for nodejs which introduce GraphQL type system for describing schema *(definition over configuration)* and executes queries on the server side. [express-graphql](https://github.com/graphql/express-graphql) is a HTTP server which gets request data, passes it to `graphql-js` and returned result passes to response.\n\n**`graphql-compose`** – the *imperative tool* which worked on top of `graphql-js`. It provides some methods for creating types and GraphQL Models (so I call types with a list of common resolvers) for further building of complex relations in your schema.\n- provides methods for editing GraphQL output/input types (add/remove fields/args/interfaces)\n- introduces `Resolver`s – the named graphql fieldConfigs, which can be used for finding, updating, removing records\n- provides an easy way for creating relations between types via `Resolver`s\n- provides converter from `OutputType` to `InputType`\n- provides `projection` parser from AST\n- provides `GraphQL schema language` for defining simple types\n- adds additional types `Date`, `Json`\n\n\n**`graphql-compose-[plugin]`** – is a *declarative generators/plugins* that build on top of `graphql-compose`, which take some ORMs, schema definitions and creates GraphQL Models from them or modify existed GraphQL Types.\n\nType generator plugins:\n- [graphql-compose-json](https://github.com/graphql-compose/graphql-compose-json) - generates GraphQL type from JSON (a good helper for wrapping REST APIs)\n- [graphql-compose-mongoose](https://github.com/graphql-compose/graphql-compose-mongoose) - generates GraphQL types from mongoose (MongoDB models) with Resolvers.\n- [graphql-compose-elasticsearch](https://github.com/graphql-compose/graphql-compose-elasticsearch) - generates GraphQL types from elastic mappings; ElasticSearch REST API proxy via GraphQL.\n- [graphql-compose-aws](https://github.com/graphql-compose/graphql-compose-aws) - expose AWS Cloud API via GraphQL\n\nUtility plugins:\n- [graphql-compose-relay](https://github.com/graphql-compose/graphql-compose-relay) - reassemble GraphQL types with `Relay` specific things, like `Node` type and interface, `globalId`, `clientMutationId`.\n- [graphql-compose-connection](https://github.com/graphql-compose/graphql-compose-connection) - generates `connection` Resolver from `findMany` and `count` Resolvers.\n- [graphql-compose-dataloader](https://github.com/stoffern/graphql-compose-dataloader) - add DataLoader to graphql-composer resolvers.\n- [graphql-compose-recompose](https://github.com/digithun/graphql-compose-recompose) - utility that wrap GraphQL compose to high order functional pattern [work in process].\n\n## Documentation\n- [Installation](docs/02-installation)\n- [Quick Start Guide](docs/03-guide)\n- [API Reference](docs/04-api-reference)\n- [Plugins](docs/05-plugins)\n- [Advanced](docs/06-advanced)\n\n## Live Demos\n- [graphql-compose.herokuapp.com](https://graphql-compose.herokuapp.com/) - Live demo of GraphQL Server (9 models, 14 files, ~750 LOC)\n- [nodkz.github.io/relay-northwind](https://nodkz.github.io/relay-northwind) - Live demo of Relay client working with the server above (8 crazy pages, 47 files, ~3000 LOC)\n\n## Example\ncity.js\n```js\nimport { TypeComposer} from 'graphql-compose';\nimport { CountryTC } from './country';\n\nexport const CityTC = TypeComposer.create(`\n  type City {\n    code: String!\n    name: String!\n    population: Number\n    countryCode: String\n    tz: String\n  }\n`);\n\n// Define some additional fields\nCityTC.addFields({\n  ucName: { // standard GraphQL like field definition\n    type: GraphQLString,\n    resolve: (source) => source.name.toUpperCase(),\n  },\n  currentLocalTime: { // extended GraphQL Compose field definition\n    type: 'Date',\n    resolve: (source) => moment().tz(source.tz).format(),\n    projection: { tz: true }, // load `tz` from database, when requested only `localTime` field\n  },\n  counter: 'Int', // shortening for only type definition for field\n  complex: `type ComplexType {\n    subField1: String\n    subField2: Float\n    subField3: Boolean\n    subField4: ID\n    subField5: JSON\n    subField6: Date\n  }`,\n  list0: {\n    type: '[String]',\n    description: 'Array of strings',\n  },\n  list1: '[String]',\n  list2: ['String'],\n  list3: [new GraphQLOutputType(...)],\n  list4: [`type Complex2Type { f1: Float, f2: Int }`],\n});\n\n// Add resolver method\nCityTC.addResolver({\n  kind: 'query',\n  name: 'findMany',\n  args: {\n    filter: `input CityFilterInput {\n      code: String!\n    }`,\n    limit: {\n      type: 'Int',\n      defaultValue: 20,\n    },\n    skip: 'Int',\n    // ... other args if needed\n  },\n  type: [CityTC], // array of cities\n  resolve: async ({ args, context }) => {\n    return context.someCityDB\n      .findMany(args.filter)\n      .limit(args.limit)\n      .skip(args.skip);\n  },\n});\n\n// Add relation between City and Country by `countryCode` field.\nCityTC.addRelation( // GraphQL relation definition\n  'country',\n  () => ({\n    resolver: CountryTC.getResolver('findOne'),\n    args: {\n      filter: source => ({ code: `${source.countryCode}` }),\n    },\n    projection: { countryCode: true },\n  })\n);\n\n// Remove `tz` field from schema\nCityTC.removeField('tz');\n\n// Add description to field\nCityTC.extendField('name', {\n  description: 'City name',\n});\n```\n\nschema.js\n```js\nimport { GQC } from 'graphql-compose';\nimport { CityTC } from './city';\nimport { CountryTC } from './country';\n\nGQC.rootQuery().addFields({\n  cities: CityTC.getResolver('findMany'),\n  country: CountryTC.getResolver('findOne'),\n  currentTime: {\n    type: 'Date',\n    resolve: () => Date.now(),\n  },\n});\n\nGQC.rootMutation().addFields({\n  createCity: CityTC.getResolver('createOne'),\n  updateCity: CityTC.getResolver('updateById'),\n  ...adminAccess({\n    removeCity: CityTC.getResolver('removeById'),\n  }),\n});\n\nfunction adminAccess(resolvers) {\n  Object.keys(resolvers).forEach((k) => {\n    resolvers[k] = resolvers[k].wrapResolve(next => rp => {\n      // rp = resolveParams = { source, args, context, info }\n      if (!rp.context.isAdmin) {\n        throw new Error('You should be admin, to have access to this action.');\n      }\n      return next(rp);\n    });\n  });\n  return resolvers;\n}\n\nexport default GQC.buildSchema();\n```\n\n\n## License\n[MIT](https://github.com/graphql-compose/graphql-compose/blob/master/LICENSE.md)\n","readmeFilename":"README.md","gitHead":"2c101ad36dbd2b26227a9dadead0e87936ce0549","_id":"graphql-compose@3.0.0-beta.3","_npmVersion":"5.6.0","_nodeVersion":"9.5.0","_npmUser":{"name":"nodkz","email":"pavel.chertorogov@gmail.com"},"dist":{"integrity":"sha512-AcNeer//YBAsLM096Ole7WKraLtvAxaNYYZzy8sayR4R3m7+8P4sS7FygqbCwDIynfUX4i9a0ew3WhkebDoTxw==","shasum":"7b1ee91bcf4cb0ded692db1e2cb93de4c9072ea7","tarball":"http://registry-npm.ywwl.com/graphql-compose/download/graphql-compose-3.0.0-beta.3.tgz","fileCount":83,"unpackedSize":328518,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDWPZVQ9NRih0iqy4DGwgZuux2mg0mS58E+7AKxw+TlNAIgIzme7hK/R3rH3V1E0cKR30kReQi1KZBNbyfeq1RR0+4="}],"size":58021,"noattachment":false,"key":"/graphql-compose/-/graphql-compose-3.0.0-beta.3.tgz"},"maintainers":[{"name":"nodkz","email":"pavel.chertorogov@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/graphql-compose_3.0.0-beta.3_1518192730133_0.4139258787228117"},"_hasShrinkwrap":false,"publish_time":1518192731057,"_cnpm_publish_time":1518192731057,"dist-tags":{"alpha":"8.0.0-alpha.2","latest":"9.3.0","v6-latest":"6.3.8"}}