{"id":13454275,"url":"https://github.com/devknoll/graphql-schema","last_synced_at":"2025-03-24T05:33:25.696Z","repository":{"id":34558283,"uuid":"38503640","full_name":"devknoll/graphql-schema","owner":"devknoll","description":"Create GraphQL schemas with a fluent/chainable interface","archived":true,"fork":false,"pushed_at":"2015-09-22T16:26:23.000Z","size":233,"stargazers_count":137,"open_issues_count":3,"forks_count":8,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-11T23:35:23.251Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/devknoll.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}},"created_at":"2015-07-03T17:25:43.000Z","updated_at":"2024-06-08T17:05:29.000Z","dependencies_parsed_at":"2022-09-08T15:01:01.102Z","dependency_job_id":null,"html_url":"https://github.com/devknoll/graphql-schema","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/devknoll%2Fgraphql-schema","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devknoll%2Fgraphql-schema/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devknoll%2Fgraphql-schema/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devknoll%2Fgraphql-schema/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/devknoll","download_url":"https://codeload.github.com/devknoll/graphql-schema/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245217352,"owners_count":20579290,"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":[],"created_at":"2024-07-31T08:00:52.530Z","updated_at":"2025-03-24T05:33:25.382Z","avatar_url":"https://github.com/devknoll.png","language":"JavaScript","readme":"graphql-schema\n==============\n\nCreate GraphQL schemas with a fluent/chainable interface.\n\n**Notice to \u003c=0.3.0 users:**\n\nThe API has been changed significantly. Rather than hacking ES7 classes, `graphql-schema` now implements a fluent/chainable API. As a bonus, we can define entire schemas.\n\n## Installation\n\n    npm install graphql-schema\n\n## Basic Usage\n\n```js\nconst rootQueryType = objectType('RootQueryType', 'TODO: Description')\n  .field('hello', GraphQLString, 'Say hello to someone')\n    .arg('name', GraphQLString, 'The name of the person to say hello to')\n    .resolve(root, {name} =\u003e `Hello, ${name}`)\n  .end();\n```\n\nbecomes\n\n```js\nvar rootQueryType = new GraphQLObjectType({\n  name: 'RootQueryType',\n  description: 'TODO: Description'\n  fields: {\n    hello: {\n      type: GraphQLString,\n      description: 'Say Hello to someone',\n      args: {\n        name: {\n          name: 'name',\n          type: GraphQLString,\n          description: 'The name of the person to say Hello to'\n        }\n      }\n      resolve: (root, {name}) =\u003e `Hello, ${name}`;\n    }\n  }\n});\n```\n\n## Full Example\n\n```js\nimport { interfaceType, objectType, enumType, schemaFrom, listOf, notNull } from 'graphql-schema';\n\nconst episodeEnum = enumType('Episode',\n    'One of the films in the Star Wars Trilogy')\n  .value('NEWHOPE', 4, 'Released in 1977.')\n  .value('EMPIRE', 5, 'Released in 1980.')\n  .value('JEDI', 6, 'Released in 1983.')\n  .end();\n\nconst characterInterface = interfaceType('Character',\n    'A character in the Star Wars Trilogy')\n  .field('id', notNull(GraphQLString), 'The id of the character.')\n  .field('name', GraphQLString, 'The name of the character.')\n  .field('friends', listOf(characterInterface),\n    'The friends of the character, or an empty list if they have none')\n  .field('appearsIn', listOf(episodeEnum), 'Which movies they appear in.')\n  .resolve((obj) =\u003e {\n    if (starWarsData.Humans[obj.id] !== undefined) {\n      return humanType;\n    }\n    if (starWarsData.Droids[obj.id] !== undefined) {\n      return droidType;\n    }\n    return null;\n  })\n  .end();\n\nconst humanType = objectType('Human', [characterInterface],\n    'A humanoid creature in the Star Wars universe.')\n  .field('id', notNull(GraphQLString), 'The id of the human.')\n  .field('name', GraphQLString, 'The name of the human.')\n  .field('friends', listOf(characterInterface),\n    'The friends of the human, or an empty list if they have none', (human) =\u003e {\n      return getFriends(human);\n    })\n  .field('appearsIn', listOf(episodeEnum), 'Which movies they appear in.')\n  .field('homePlanet', GraphQLString,\n    'The home planet of the human, or null if unknown.')\n  .end();\n\nconst droidType = objectType('Droid', [characterInterface],\n    'A mechanical creature in the Star Wars universe.')\n  .field('id', notNull(GraphQLString), 'The id of the droid.')\n  .field('name', GraphQLString, 'The name of the droid.')\n  .field('friends', listOf(characterInterface),\n    'The friends of the droid, or an empty list if they have none', (droid) =\u003e {\n      return getFriends(droid);\n    })\n  .field('appearsIn', listOf(episodeEnum), 'Which movies they appear in.')\n  .field('primaryFunction', GraphQLString, 'The primary function of the droid.')\n  .end();\n\nconst queryType = objectType('Query')\n  .field('hero', characterInterface, () =\u003e artoo)\n  .field('human', humanType)\n    .arg('id', notNull(GraphQLString))\n    .resolve((root, {id}) =\u003e starWarsData.Humans[id])\n  .field('droid', droidType)\n    .arg('id', notNull(GraphQLString))\n    .resolve((root, {id}) =\u003e starWarsData.Droids[id])\n  .end();\n\nconst mutationType = objectType('Mutation')\n  .field('updateCharacterName', characterInterface)\n    .arg('id', notNull(GraphQLString))\n    .arg('newName', notNull(GraphQLString))\n    .resolve((root, {id, newName}) =\u003e updateCharacterName(id, newName))\n  .end();\n\nconst starWarsSchema = schemaFrom(queryType, mutationType);\n```\n\n# Cyclic Types\n\n`graphql-schema` supports cyclic types. Instead of passing in a reference, just pass in a function instead:\n\n```js\nconst userType = objectType('User')\n  .field('friends', () =\u003e listOf(userType))\n  .end();\n```\n\n## API\n\n### enumType(name, description)\n\nDefine a new `GraphQLEnumType`\n\n##### .value(name, value, description)\n##### .deprecated(deprecationReason)\n\n### interfaceType(name, description)\n\nDefine a new `GraphQLInterfaceType`.\n\n##### .field(name, type, description)\n##### .deprecated(deprecationReason)\n##### .arg(name, type, defaultValue, description)\n##### .resolve(fn)\n\n### objectType(name, [interfaces], description)\n\nDefine a new `GraphQLObjectType`.\n\n##### .field(name, type, description)\n##### .deprecated(deprecationReason)\n##### .arg(name, type, defaultValue, description)\n##### .resolve(fn)\n\n## schemaFrom(queryRootType, mutationRootType)\n\nDefine a new `GraphQLSchema` from the given root types.\n\n## listOf(type)\n\nDefine a new `GraphQLList(type)`.\n\n## notNull(type)\n\nDefine a new `GraphQLNonNull(type)`.\n\n# Thanks\n\nThanks to [Florent Cailhol](https://github.com/ooflorent) for the chainable interface idea!","funding_links":[],"categories":["Libraries","JavaScript","Community","\u003ca name=\"JavaScript\"\u003e\u003c/a\u003eJavaScript"],"sub_categories":["JavaScript Libraries"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevknoll%2Fgraphql-schema","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdevknoll%2Fgraphql-schema","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevknoll%2Fgraphql-schema/lists"}