{"id":13499655,"url":"https://github.com/xpepermint/graphql-example","last_synced_at":"2025-10-09T21:37:49.862Z","repository":{"id":146091878,"uuid":"74179156","full_name":"xpepermint/graphql-example","owner":"xpepermint","description":"Intuitive GraphQL Resolver Example - Application example using RawModel.js as GraphQL rootValue on steroids.","archived":false,"fork":false,"pushed_at":"2023-02-10T02:47:01.000Z","size":139,"stargazers_count":25,"open_issues_count":3,"forks_count":14,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-09-17T12:45:26.495Z","etag":null,"topics":["example","graphql","graphql-application","graphql-query","graphql-rootvalue","graphql-server","model","rawmodel","resolver"],"latest_commit_sha":null,"homepage":"https://github.com/xpepermint/rawmodeljs","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xpepermint.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":"2016-11-19T01:21:56.000Z","updated_at":"2021-12-09T07:22:47.000Z","dependencies_parsed_at":"2024-01-15T00:55:05.319Z","dependency_job_id":"85bdc455-202f-4e8f-8fb0-d186ce583c4e","html_url":"https://github.com/xpepermint/graphql-example","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/xpepermint/graphql-example","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xpepermint%2Fgraphql-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xpepermint%2Fgraphql-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xpepermint%2Fgraphql-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xpepermint%2Fgraphql-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xpepermint","download_url":"https://codeload.github.com/xpepermint/graphql-example/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xpepermint%2Fgraphql-example/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279002054,"owners_count":26083286,"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","status":"online","status_checked_at":"2025-10-09T02:00:07.460Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["example","graphql","graphql-application","graphql-query","graphql-rootvalue","graphql-server","model","rawmodel","resolver"],"created_at":"2024-07-31T22:00:37.641Z","updated_at":"2025-10-09T21:37:49.840Z","avatar_url":"https://github.com/xpepermint.png","language":"JavaScript","readme":"# graphql-example\n\n\u003e Intuitive GraphQL Resolver Example - Application example using RawModel.js as GraphQL rootValue on steroids.\n\n`GraphQL` is a modern replacement for the well known REST API server. This is a pure GraphQL server application - an example API server.\n\n## Features\n\n\u003e This example uses Node.js v7 and MongoDB.\n\n* GraphQL rootValue using [RawModel.js](https://github.com/xpepermint/rawmodeljs).\n* Nested schema.\n* Print GraphQL schema from command-line.\n* Execute GraphQL schema from command-line.\n* Input data validation.\n* Context-aware models.\n* Graphql HTTP server.\n* MongoDB connector (an example how to use a database connector).\n\n## Pre-requisites\n\n- Make sure you are using Node.js v7+.\n- Install and start MongoDB server.\n\n## Build Setup\n\n```\n# install dependencies\nnpm install\n\n# start the server (GraphiQL is started at http://127.0.0.1:3000)\nnpm start\n\n# use nodemon in development to automatically reload the server on changes\nnpm install -g nodemon\nnodemon --exec npm start\n\n# run GraphQL query from command-line\nnpm run exec '{getUsers {id name}}'\n\n# run tests\nnpm test\n```\n\n## Run\n\n`npm start`\n\nStarts [GraphiQL server](https://medium.com/the-graphqlhub/graphiql-graphql-s-killer-app-9896242b2125#.xt4jo8bet) at `http://127.0.0.1:3000/`\n\n## Query Examples\n\n```js\nmutation { # create new user\n  createUser(name: \"\") {\n    id\n    name\n    errors {\n      path\n      errors {\n      \tvalidator\n      \tmessage\n      \tcode\n      }\n    }\n  }\n}\n```\n\n```js\nquery { # get users\n  getUsers(skip: 0, limit: 5) {\n    id\n    name\n  }\n}\n```\n\n## Architecture\n\n```\n|- /config    - config files\n|- /scripts   - scripts that can be executed from CLI (used by `package.json`)\n|- /src\n  |- /graph`    - GraphQL application\n  |- /http      - HTTP server\n  |- /lib       - general helpers (e.g. Mongo DB connector)\n  |- index.js   - application main file\n- /tests        - tests written in [ava](https://github.com/avajs/ava) framework\n```\n\nThe application exports two main classes - `Graph` (GraphQL application - `src/http`) and `HTTP` (HTTP server - `src/graph`). Each class represents a stand-alone application. You could create two separated npm packages from this to further split your code to responsibilities.\n\nThe scripts in the `./src/scripts` folder use these classes to print GraphQL schema, execute GraphQL query and start the HTTP server from the command-line. These scripts are used by the `package.json` file thus you can use the `npm run {script-name}` commands.\n\nGraph application describes your data model and provides a communication layer. HTTP application exposes GraphQL application over HTTP thus users can use the GraphQL application as your API endpoint.\n\nThe HTTP server is based on [express-graphql](https://github.com/graphql/express-graphql) which is a bridge to communicate with a GraphQL application via [Express](http://expressjs.com/) HTTP server. You could substitute this with [koa-graphql](https://github.com/chentsulin/koa-graphql) or [koa-graphql-next](https://github.com/bidanjun/koa-graphql-next). The `express-graphql` middleware includes a [GraphiQL](https://github.com/graphql/graphiql) user interface which is a generic interface for running GraphQL queries and mutations (for use in development).\n\nGraph application exposes the API over the GraphQL schema defined in `./src/graph/schema/index.graphql`. It uses the  [RawModel.js](https://github.com/xpepermint/rawmodeljs#context--graphql) for describing and validating input data. To keep the example simple, we only have two models here where the `Root` model represents a GraphQL resolver - the [rootValue](http://graphql.org/code/) for GraphQL.\n\n## GraphQL Clients\n\nYour front-end application will need a `GraphQL client` to communicate with a GraphQL server. You can also use a raw browser's `fetch` to post data to the GraphQL server.\n\nPopular GraphQL clients (you can add your own):\n\n* [FetchQL](https://github.com/gucheen/FetchQL)\n* [lokka](https://github.com/kadirahq/lokka)\n* [apollo-client](https://github.com/apollostack/apollo-client)\n\n## Tutorials\n\nNode.js tutorials: [Node.js Cheatsheet](https://xpepermint.gitbooks.io/nodejs-cheatsheet/)\n","funding_links":[],"categories":["Examples"],"sub_categories":["JavaScript Examples"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxpepermint%2Fgraphql-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxpepermint%2Fgraphql-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxpepermint%2Fgraphql-example/lists"}