{"id":15292810,"url":"https://github.com/taylorgoolsby/graphql-directive-connection","last_synced_at":"2025-05-07T03:45:12.928Z","repository":{"id":33424225,"uuid":"158323513","full_name":"taylorgoolsby/graphql-directive-connection","owner":"taylorgoolsby","description":"Generate relay connections by marking fields with a @connection directive.","archived":false,"fork":false,"pushed_at":"2023-07-06T03:46:22.000Z","size":691,"stargazers_count":13,"open_issues_count":5,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-07T03:45:12.492Z","etag":null,"topics":["connection","directive","graphql","relay","schema","sdl"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/graphql-directive-connection","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/taylorgoolsby.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-11-20T03:07:35.000Z","updated_at":"2023-09-15T01:45:36.000Z","dependencies_parsed_at":"2024-10-23T03:11:18.851Z","dependency_job_id":null,"html_url":"https://github.com/taylorgoolsby/graphql-directive-connection","commit_stats":{"total_commits":48,"total_committers":5,"mean_commits":9.6,"dds":"0.39583333333333337","last_synced_commit":"f0d55499bab984c8502960b0012a77bb7aa1e119"},"previous_names":["taylrun/graphql-directive-connection","taylorgoolsby/graphql-directive-connection","mgs485/graphql-directive-connection"],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/taylorgoolsby%2Fgraphql-directive-connection","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/taylorgoolsby%2Fgraphql-directive-connection/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/taylorgoolsby%2Fgraphql-directive-connection/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/taylorgoolsby%2Fgraphql-directive-connection/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/taylorgoolsby","download_url":"https://codeload.github.com/taylorgoolsby/graphql-directive-connection/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252810273,"owners_count":21807759,"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":["connection","directive","graphql","relay","schema","sdl"],"created_at":"2024-09-30T16:27:28.994Z","updated_at":"2025-05-07T03:45:12.907Z","avatar_url":"https://github.com/taylorgoolsby.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# graphql-directive-connection\n\nThis package generates relay connections by marking fields with a `@connection` directive, and then passing your SDL through `applyConnectionTransform`.\n\n## Example\n\n```js\nimport sqlDirective from 'graphql-to-sql'\nimport privateDirective from 'graphql-directive-private'\nimport connectionDirective from 'graphql-directive-connection'\nimport { makeExecutableSchema } from '@graphql-tools/schema'\n\nconst { generateSql } = sqlDirective('sql')\nconst { privateDirectiveTransform } = privateDirective('private')\nconst { connectionDirectiveTransform } = connectionDirective('connection')\n\nconst typeDefs = `\n  directive @connection on FIELD_DEFINITION\n  directive @private on OBJECT | FIELD_DEFINITION\n\n  type User {\n    userId: Int @sql(type: \"BINARY(16)\", primary: true)\n    password: String @sql(type: \"VARCHAR(255)\", primary: true) @private\n    \n    # Tag the field with @connection. Its return type will be replaced with PostConnection.\n    posts: [Post!]! @connection\n  }\n\n  type Post {\n    postId: Int @sql(type: \"BINARY(16)\", primary: true)\n  }\n\n  type Query {\n    user: User\n  }\n`\n\nexport const sql = generateSql({typeDefs}, {\n  databaseName: 'public',\n  tablePrefix: 'test_',\n  dbType: 'mysql',\n})\n\nlet schema = makeExecutableSchema({\n  typeDefs\n})\n\nschema = privateDirectiveTransform(schema)\nschema = connectionDirectiveTransform(schema)\n\nexport default schema\n```\n\nIt will:\n* Create the needed Connection and Edge object types.\n* Reassign the type of marked fields to the Connection type.\n* Remove any `@connection` directives.\n* Generate the PageInfo object type if it hasn't been defined.\n* Throw errors if the generated Connection and Edge types have a name conflict with types already defined in your SDL.\n* Leave everything else in your SDL untouched.\n\nThese types will be added to your schema:\n\n```graphql\ntype PageInfo {\n  hasNextPage: Boolean!\n  hasPreviousPage: Boolean!\n  startCursor: String\n  endCursor: String\n}\n\ntype PostEdge {\n  cursor: String!\n  node: Post\n}\n\ntype PostConnection {\n  totalCount: Int!\n  edges: [PostEdge]\n  pageInfo: PageInfo!\n}\n```\n\n## cacheControl\n\nBy default, the `cacheControl` directives are not generated on Edge object types and inside connection fields which results in cache arguments being completely ignored.\nEnabling `defaultMaxAge` for all types/fields across your GraphQL implementation partially solve the problem, however it might not be the best options.\nIt is possible to enable `cacheControl` directive support by passing a `useCacheControl: true` flag to `applyConnectionTransform` function.\nThe package will then use the largest `maxAge` across the connection fields with custom types and apply it to `edges` and `pageInfo` fields along with the `Edge` type.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftaylorgoolsby%2Fgraphql-directive-connection","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftaylorgoolsby%2Fgraphql-directive-connection","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftaylorgoolsby%2Fgraphql-directive-connection/lists"}