{"id":22807977,"url":"https://github.com/almost-full-stack/graphcraft","last_synced_at":"2025-08-22T00:32:21.859Z","repository":{"id":40672442,"uuid":"138157096","full_name":"almost-full-stack/graphcraft","owner":"almost-full-stack","description":"Rapildy build and extend GraphQL API based on Sequelize models. This library helps you focus on business logic while taking care of GraphQL schema automatically.","archived":false,"fork":false,"pushed_at":"2024-02-17T13:23:21.000Z","size":1799,"stargazers_count":51,"open_issues_count":9,"forks_count":19,"subscribers_count":6,"default_branch":"develop","last_synced_at":"2024-12-12T11:07:24.018Z","etag":null,"topics":["graphql","graphql-js","microservices","sequelize","sequelize-graphql-schema","sequelize-model","sequelize-models","serverless"],"latest_commit_sha":null,"homepage":"https://almost-full-stack.github.io/graphcraft/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/almost-full-stack.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-06-21T10:42:39.000Z","updated_at":"2024-04-09T13:59:48.000Z","dependencies_parsed_at":"2023-11-18T03:51:08.189Z","dependency_job_id":"e74da5b6-59c9-438f-a105-14de32069bdc","html_url":"https://github.com/almost-full-stack/graphcraft","commit_stats":{"total_commits":392,"total_committers":13,"mean_commits":"30.153846153846153","dds":"0.47959183673469385","last_synced_commit":"116997b016b9d758654c0f392f9aa00726f9bab5"},"previous_names":["almost-full-stack/sequelize-graphql-schema"],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/almost-full-stack%2Fgraphcraft","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/almost-full-stack%2Fgraphcraft/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/almost-full-stack%2Fgraphcraft/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/almost-full-stack%2Fgraphcraft/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/almost-full-stack","download_url":"https://codeload.github.com/almost-full-stack/graphcraft/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230542289,"owners_count":18242332,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["graphql","graphql-js","microservices","sequelize","sequelize-graphql-schema","sequelize-model","sequelize-models","serverless"],"created_at":"2024-12-12T11:07:26.113Z","updated_at":"2024-12-20T06:07:15.760Z","avatar_url":"https://github.com/almost-full-stack.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# GraphCraft\n### This repository and package is renamed to graphcraft.\n\n\n[![npm version](https://badge.fury.io/js/graphcraft.svg)](https://www.npmjs.com/package/graphcraft)\n[![dependencies](https://david-dm.org/almost-full-stack/graphcraft.svg)](https://github.com/almost-full-stack/graphcraft)\n[![devdependencies](https://david-dm.org/almost-full-stack/graphcraft.svg?type=dev)](https://github.com/almost-full-stack/graphcraft)\n[![Build Status](https://github.com/almost-full-stack/graphcraft/workflows/codecheck/badge.svg?branch=develop)](https://github.com/almost-full-stack/graphcraft/actions)\n\nRapildy build and extend GraphQL API based on [Sequelize](https://github.com/sequelize/sequelize \"Sequelize\") models. This library helps you focus on business logic while taking care of GraphQL schema automatically.\n[https://almost-full-stack.github.io/graphcraft/](https://almost-full-stack.github.io/graphcraft/http:// \"https://almost-full-stack.github.io/graphcraft/\")\n\nIf you are updating from a previous version to `1.0` read notes at the end to fix breaking changes it will cause.\n\n## Installation\n\n```bash\nnpm install graphcraft\n```\n\n## Prerequisites\n\nThis package assumes you have `graphql` and `sequelize` already installed (both packages are declared as `peerDependencies`).\n\nThis library uses two set of configurations, **Library Options** and **Model Options**.\n\n## Library Options\nThese options are defined globally and are applied throughout schema and all models.\n```javascript\n/**\n * naming convention for mutations/queries and types.\n * {name} = Model Name or type name\n * {type} = Get | Create | Update | Delete\n * {bulk} = Bulk for bulk operations only\n * */\n   \nnaming: {\n  pascalCase: true, // applied everywhere, set to true if you want to use camelCase\n  queries: '{name}{type}', // applied to auto generated queries\n  mutations: '{name}{type}{bulk}', // applied to auto generated mutations\n  input: '{name}', // applied to all input types\n  rootQueries: 'RootQueries',\n  rootMutations: 'RootMutations',\n  // {type} and {bulk} will be replaced with one of the following\n  type: {\n    create: 'Create',\n    update: 'Update',\n    delete: 'Delete',\n    restore: 'Restore',\n    byPk: 'ByPK',\n    get: '',\n    bulk: 'Bulk',\n    count: 'Count',\n    default: 'Default'\n  }\n}\n```\n```javascript\n// default limit to be applied on find queries\nlimits: {\n  default: 50, // default limit. use 0 for no limit\n  max: 100, // maximum allowed limit. use 0 for unlimited\n  nested: false // whether to apply these limits on nested/sub types or not\n}\n```\n```javascript\n// nested objects can be passed and will be mutated automatically. Only hasMany and belongsTo relation supported.\nnestedMutations: true, // doesn't work with add bulk mutation\n\n/**\n * update modes when sending nested association objects\n * UPDATE_ONLY \u003e update only incoming records\n * UPDATE_ADD \u003e update existing records and add new ones i.e [{id: 1, name: 'test'}, {name: 'test2'}] record[0] will be updated and record[1] will be added\n * UPDATE_ADD_DELETE \u003e not recommended: update existing records, add new ones and delete non-existent records i.e [{id: 1, name: 'test'}, {name: 'test2'}] record[0] will be updated, record[1] will be added, anything else will be deleted\n * MIXED \u003e i.e [{id: 1, name: 'test'}, {id:2}, {name: 'test2'}], record[0] will be updated, record[1] will be deleted and record[2] will be added\n * IGNORE \u003e ignore nested update\n */\n\nnestedUpdateMode: 'MIXED',\n```\n```javascript\n// applied globaly on both auto-generated and custom queries/mutations.\n// only specified queries/ and mutations would be exposed via api\nexposeOnly: {\n  queries: [],\n  mutations: [],\n  // instead of not generating queries/mutations this will instead throw an error.\n  throw: false // string message\n}\n```\n```javascript\n// these models will be excluded from graphql schema\nexclude: [], // ['Product'] this will exclude all queries/mutations for Product model.\n```\n```javascript\n// include these arguments to all queries/mutations\nincludeArguments: {}, // {'scopeId': 'int'} this will add scopeId in arguments for all queries and mutations\n```\n```javascript\n// enabled/disable dataloader for nested queries\ndataloader: false, // use dataloader for queries. Uses dataloader-sequelize\n```\n```javascript\n// mutations are run inside transactions. Transactions are accessible in extend hook.\ntransactionedMutations: true,\n```\n```javascript\n// generic or those types/queries/mutations which are not model specific\nimportTypes: {}, // use this to import other non-supported graphql types such as Upload or anyother\ntypes: {}, // custom graphql types\nqueries: {}, // custom queries\nmutations: {}, // custom mutations\n```\n```javascript\n// global hooks, behaves same way as model before/extend\nglobalHooks: {\n  before: {}, // will be executed before all auto-generated mutations/queries (fetch/create/update/destroy)\n  extend: {} // will be executed after all auto-generated mutations/queries (fetch/create/update/destroy)\n},\n```\n```javascript\nfindOneQueries: false, // create a find one query for each model (i.e. ProductByPk), which takes primary key (i.e. id) as argument and returns one item. Can also pass an array of models to create for specific models only (i.e. ['Product', 'Image'])\n```\n```javascript\nfetchDeleted: false, // Globally when using queries, this will allow to fetch both deleted and undeleted records (works only when tables have paranoid option enabled)\nrestoreDeleted: false, // Applies globally, create restore endpoint for deleted records\n```\n```javascript\n// data, source, args, context, info are passed as function arguments\n// executes after all queries/mutations\nlogger() {\n  return Promise.resolve();\n},\n```\n```javascript\n// your custom authorizer\n// executes before all queries/mutations\nauthorizer() {\n  return Promise.resolve();\n},\n```\n```javascript\n// these error messages are used when certain exceptions are thrown\n// must be used with errorHandler function exposed via library\nerrorHandler: {\n  'ETIMEDOUT': { statusCode: 503 }\n}\n```\n\n\n```javascript\nconst options = {\n  exclude: [\"payments\"],\n  authorizer: function authorizer(source, args, context, info) {\n    const { fieldName } = info; // resource name\n\n    return Promise.resolve();\n  }\n};\n\nconst { generateSchema } = require(\"graphcraft\")(options);\n```\n\n## Model Options\nFollowing options are model specific options, must be accessible via `model.graphql` property.\n\n```javascript\n// manipulate your model attributes\nattributes: {\n// list attributes which are to be ignored in Model Input\n  exclude: [], // ['id', 'createdAt'], these fields will be excluded from GraphQL Schema\n// attributes in key:type format which are to be included in Model Input\n  include: {}, // {'customKey': 'string'} this extra field will be added in GraphQL schema\n},\n```\n```javascript\n// scope usage is highy recommended.\n// common scope to be applied on all find/update/destroy operations\nscopes: null, \n// 'scopes': ['scope', 'args.scopeId'] this will pass value of args.scopeId to model scope\n// values can be either picked from args or context\n```\n```javascript\n// rename default queries/mutations to specified custom name\nalias: {},\n// {'fetch': 'productGet', 'create': 'productAdd', 'update': ..., 'destroy': ....}\n```\n```javascript\nbulk: { // OR bulk: ['create', 'destroy', ....]\n  enabled: [], // enable bulk options ['create', 'destroy', 'update']\n  // Use bulkColumn when using bulk option for 'create' and using returning true to increase efficiency.\n  bulkColumn: false, // bulk identifier column, when bulk creating this column will be auto filled with a uuid and later used to fetch added records 'columnName' or ['columnName', true] when using a foreign key as bulk column\n  returning: true // This will return all created/updated items, doesn't use sequelize returning option.\n}\n```\n```javascript\ntypes: {}, // user defined custom types\nmutations: {}, // user defined custom mutations\nqueries: {}, // user defined custom queries\n```\n```javascript\n// exclude one or more default mutations ['create', 'destroy', 'update']\nexcludeMutations: [],\nexcludeQueries: [], // exclude one or more default queries ['fetch']\n```\n```javascript\n// HOOKS\n// each hook must return a promise.\n// extend/after hook default queries/mutations behavior {fetch, create, destroy, update}\n// (data, source, args, context, info) are passed to extend\nextend: {},\n// before hook for default queries/mutations behavior {fetch, create, destroy, update}\n// (source, args, context, info) arguments are passed to before\nbefore: {},\n// overwrite default queries/mutations behavior {fetch, create, destroy, update}\n// overwrite hooks are passed (source, args, context, info) arguments\noverwrite: {},\njoins: false // make a query using join (left/right/inner) instead of batch dataloader, join will appear in all subtype args. Right join won't work for sqlite\n```\n```javascript\nreadonly: false, // exclude create/delete/update mutations automatically\n```\n```javascript\nfetchDeleted: false, // same as fetchDeleted as global except it lets you override global settings\nrestoreDeleted: false // same as restoreDeleted as global except it lets you override global settings\n```\n```javascript\n// define hooks to be invoked on find queries {before, after}\nfind: {}\n```\n### Usage in Model\n```javascript\nProduct.graphql = {\n    attributes: {\n        exclude: ['description'],\n        include: { modelPortfolioId: 'int', obj: 'myObj' },\n    },\n    ...REST_OF_OPTIONS\n};\n```\n\n## Usage\n\n```javascript\nconst {generateModelTypes, generateSchema} = require('graphcraft')(options);\nconst models = require('./models')\nconst schema = await generateSchema(models) // Generates the schema, return promise.\n```\n\n### Example with Express\n\n```javascript\nconst { GraphQLSchema } = require('graphql');\nconst express = require('express');\nconst graphqlHTTP = require('express-graphql');\n\nvar options = {\n  exclude: [\"Users\"]\n}\n\nconst {generateSchema} = require('graphcraft')(options);\n\nconst models = require('./models');\n\nconst app = express();\n\napp.use('/graphql', async (req, res) =\u003e {\n  \n  const schema = await generateSchema(models, req);\n\n  return graphqlHTTP({\n      schema: new GraphQLSchema(schema),\n      graphiql: true\n    })(req, res);\n\n});\n\napp.listen(8080, function() {\n  console.log('RUNNING ON 8080. Graphiql http://localhost:8080/graphql')\n})\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falmost-full-stack%2Fgraphcraft","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falmost-full-stack%2Fgraphcraft","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falmost-full-stack%2Fgraphcraft/lists"}