{"id":13516560,"url":"https://github.com/thejibz/graphql-compose-mysql","last_synced_at":"2025-03-31T06:31:24.698Z","repository":{"id":86289345,"uuid":"160523470","full_name":"thejibz/graphql-compose-mysql","owner":"thejibz","description":"Generates GraphQL types and resolvers from a MySQL database.","archived":false,"fork":false,"pushed_at":"2019-12-17T16:30:51.000Z","size":149,"stargazers_count":29,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-11-01T21:34:37.121Z","etag":null,"topics":["graphql","graphql-compose","graphql-compose-plugin"],"latest_commit_sha":null,"homepage":"","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/thejibz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2018-12-05T13:36:32.000Z","updated_at":"2024-01-24T16:09:41.000Z","dependencies_parsed_at":"2023-03-10T17:31:02.175Z","dependency_job_id":null,"html_url":"https://github.com/thejibz/graphql-compose-mysql","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thejibz%2Fgraphql-compose-mysql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thejibz%2Fgraphql-compose-mysql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thejibz%2Fgraphql-compose-mysql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thejibz%2Fgraphql-compose-mysql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thejibz","download_url":"https://codeload.github.com/thejibz/graphql-compose-mysql/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246429459,"owners_count":20775805,"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-compose","graphql-compose-plugin"],"created_at":"2024-08-01T05:01:23.573Z","updated_at":"2025-03-31T06:31:21.524Z","avatar_url":"https://github.com/thejibz.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# graphql-compose-mysql\n\nGenerates GraphQL types and resolvers from a MySQL database.\n\nAs cherry on the cake, it will also:\n* Create fields to make joins between tables (based on foreign keys detected)\n* Use Facebook's [dataloader](https://github.com/facebook/dataloader) under the hood to drastically improve querying performance*\n\n*: To avoid incoherent data, dataloaders' caching disabled, only batching feature used.\n\n## Installation\n\n```bash\nyarn install graphql graphql-compose graphql-compose-mysql\n```\n\nModules `graphql` and `graphql-compose`, are located in `peerDependencies`, so they should be installed explicitly in your app. They have global objects and should not have ability to be installed as submodules.\n\n## Sample usage\n\n```js\nconst { ApolloServer } = require(\"apollo-server\")\nconst { composeWithMysql } = require(\"graphql-compose-mysql\")\n\nasync function main() {\n    return composeWithMysql({\n        mysqlConfig: {\n            host: \"localhost\",\n            port: 3306,\n            user: \"root\",\n            password: \"secret\",\n            database: \"employees\"\n        },\n    }).then(schema =\u003e {\n        const server = new ApolloServer({\n            schema: schema,\n            playground: true,\n        })\n\n        server.listen().then(({ url }) =\u003e {\n            console.log(`🚀 Server ready at ${url}`)\n        })\n    })\n}\n\nmain()\n```\n\n`mysqlConfig` will be used internally to initialize a [mysql driver](https://github.com/mysqljs/mysql). See Available options [here](https://github.com/mysqljs/mysql#connection-options).\n\n## Tests\n## pre-requisites\nStart the needed docker containers by issuing a `docker-compose up` in the /tests/ folder.\n\nIt will spin up a MySQL database exposed on the local port 3306 and load it up with employees data from [datacharmer/test_db](\nhttps://github.com/datacharmer/test_db).\n\nYou will also get an [adminer](https://www.adminer.org/) GUI on the local port 8080.\n\n## MySQL employees' database\n![emp_erd.png](emp_erd.png)\n\n## GraphQL schema generated\nAs you can see, join's fields between tables are also created.\n\n```GraphQL\n      type current_dept_empT {\n        emp_no: Int\n        dept_no: String\n        from_date: Date\n        to_date: Date\n      }\n      \n      scalar Date\n      \n      type departmentsT {\n        dept_no: String\n        dept_name: String\n      }\n      \n      type dept_emp_latest_dateT {\n        emp_no: Int\n        from_date: Date\n        to_date: Date\n      }\n      \n      type dept_empT {\n        emp_no: Int\n        dept_no: String\n        from_date: Date\n        to_date: Date\n        departments(dept_name: String): [departmentsT]\n        employees(birth_date: Date, first_name: String, last_name: String, gender: String, hire_date: Date): [employeesT]\n      }\n      \n      type dept_managerT {\n        emp_no: Int\n        dept_no: String\n        from_date: Date\n        to_date: Date\n        departments(dept_name: String): [departmentsT]\n        employees(birth_date: Date, first_name: String, last_name: String, gender: String, hire_date: Date): [employeesT]\n      }\n      \n      type employeesT {\n        emp_no: Int\n        birth_date: Date\n        first_name: String\n        last_name: String\n        gender: String\n        hire_date: Date\n      }\n      \n      type Query {\n        current_dept_emp(emp_no: Int, dept_no: String, from_date: Date, to_date: Date): [current_dept_empT]\n        departments(dept_no: String, dept_name: String): [departmentsT]\n        dept_emp(emp_no: Int, dept_no: String, from_date: Date, to_date: Date): [dept_empT]\n        dept_emp_latest_date(emp_no: Int, from_date: Date, to_date: Date): [dept_emp_latest_dateT]\n        dept_manager(emp_no: Int, dept_no: String, from_date: Date, to_date: Date): [dept_managerT]\n        employees(emp_no: Int, birth_date: Date, first_name: String, last_name: String, gender: String, hire_date: Date): [employeesT]\n        salaries(emp_no: Int, salary: Int, from_date: Date, to_date: Date): [salariesT]\n        titles(emp_no: Int, title: String, from_date: Date, to_date: Date): [titlesT]\n      }\n      \n      type salariesT {\n        emp_no: Int\n        salary: Int\n        from_date: Date\n        to_date: Date\n        employees(birth_date: Date, first_name: String, last_name: String, gender: String, hire_date: Date): [employeesT]\n      }\n      \n      type titlesT {\n        emp_no: Int\n        title: String\n        from_date: Date\n        to_date: Date\n        employees(birth_date: Date, first_name: String, last_name: String, gender: String, hire_date: Date): [employeesT]\n      }\n```\n\n## Run tests\nAfter docker's containers are started, in root folder run:\n```bash\nyarn test\n```\n\n## License\n\n[MIT](LICENSE.md)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthejibz%2Fgraphql-compose-mysql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthejibz%2Fgraphql-compose-mysql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthejibz%2Fgraphql-compose-mysql/lists"}