{"id":13879019,"url":"https://github.com/gmac/graphql-ruby-schema-directives","last_synced_at":"2025-07-16T15:30:34.741Z","repository":{"id":56883413,"uuid":"324220638","full_name":"gmac/graphql-ruby-schema-directives","owner":"gmac","description":"Generic implementation of schema directives for GraphQL Ruby ","archived":true,"fork":false,"pushed_at":"2023-02-10T21:43:36.000Z","size":23,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-10T11:59:06.027Z","etag":null,"topics":["apollo-federation","graphql","graphql-ruby","schema-directives","schema-stitching","sdl"],"latest_commit_sha":null,"homepage":"","language":"Ruby","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/gmac.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}},"created_at":"2020-12-24T19:07:42.000Z","updated_at":"2023-02-10T21:44:35.000Z","dependencies_parsed_at":"2023-07-14T11:08:16.477Z","dependency_job_id":null,"html_url":"https://github.com/gmac/graphql-ruby-schema-directives","commit_stats":{"total_commits":10,"total_committers":2,"mean_commits":5.0,"dds":0.09999999999999998,"last_synced_commit":"64c5013bd8c8a8751f02074590832759ae9608d4"},"previous_names":["gmac/graphql-schema-directives-ruby"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/gmac/graphql-ruby-schema-directives","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gmac%2Fgraphql-ruby-schema-directives","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gmac%2Fgraphql-ruby-schema-directives/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gmac%2Fgraphql-ruby-schema-directives/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gmac%2Fgraphql-ruby-schema-directives/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gmac","download_url":"https://codeload.github.com/gmac/graphql-ruby-schema-directives/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gmac%2Fgraphql-ruby-schema-directives/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265270352,"owners_count":23738015,"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":["apollo-federation","graphql","graphql-ruby","schema-directives","schema-stitching","sdl"],"created_at":"2024-08-06T08:02:07.086Z","updated_at":"2025-07-16T15:30:34.379Z","avatar_url":"https://github.com/gmac.png","language":"Ruby","funding_links":[],"categories":["Ruby"],"sub_categories":[],"readme":"**This repository is no longer relevant**\n\n- 🚀 If you want schema directives, upgrade [`graphql-ruby`](https://github.com/rmosolgo/graphql-ruby) to v2.0.16.\n- 🧵 If you want schema stitching, use [`graphql-stitching-ruby`](https://github.com/gmac/graphql-stitching-ruby).\n\n## Ruby GraphQL Schema Directives\n\nThis gem extends [GraphQL Ruby](http://graphql-ruby.org/) to add support for custom schema directives that annotate an SDL for uses such as [Schema Stitching](https://github.com/gmac/schema-stitching-handbook/tree/master/subservice-languages/ruby). This is a more generic version of the [apollo-federation](https://github.com/Gusto/apollo-federation-ruby) gem (which is specifically tailored to setting up the [federation spec](https://www.apollographql.com/docs/federation/federation-spec/)).\n\nThis gem has some very basic goals:\n\n1. allow schema directives to be applied to any GraphQL element, and then printed as an annotated SDL.\n2. allow class-based schemas and parsed `GraphQL::Schema.from_definition` schemas to be printed together.\n\n## Contents\n\n- [Installation](#installation)\n- [Class-based schemas](#class-based-schemas)\n- [Schema from type definitions](#schema-from-type-definitions)\n\n## Installation\n\nAdd to Gemfile:\n\n```ruby\ngem 'graphql-schema_directives'\n```\n\nThen install:\n\n```shell\nbundle install\n```\n\n## Class-based schemas\n\nThere's a typed mixin available for extending all GraphQL schema members. The first thing to include is the schema mixin:\n\n```ruby\nclass MySchema \u003c GraphQL::Schema\n  include GraphQL::SchemaDirectives::Schema\nend\n```\n\nThis adds a `print_schema_with_directives` method to print an SDL that includes custom schema directives:\n\n```ruby\nMySchema.print_schema_with_directives\n```\n\n### Field, Object \u0026amp; Interface classes\n\nSetup base abstracts:\n\n```ruby\nclass BaseField \u003c GraphQL::Schema::Field\n  include GraphQL::SchemaDirectives::Field\nend\n\nclass BaseObject \u003c GraphQL::Schema::Object\n  include GraphQL::SchemaDirectives::Object\n  field_class BaseField\nend\n\nmodule BaseInterface\n  include GraphQL::Schema::Interface\n  include GraphQL::SchemaDirectives::Interface\n  field_class BaseField\nend\n```\n\nThen extend into concrete implementations:\n\n```ruby\nmodule Spaceship\n  include BaseInterface\n  add_directive :attribute, { speed: 'average' }\n\n  field :name, String, null: false, directives: {\n    cost: { value: 'FIELD' },\n    public: nil\n  }\nend\n\nclass XWing \u003c BaseObject\n  implements Spaceship\n  add_directive :attribute, { speed: 'fast' }\n  add_directive :rebel\n\n  field :name, String, null: false, directives: {\n    cost: { value: 'FIELD' },\n    public: nil\n  }\nend\n```\n\nPrints as:\n\n```graphql\ninterface Spaceship @attribute(speed: \"average\") {\n  name: String! @cost(value: \"FIELD\") @public\n}\n\ntype XWing @attribute(speed: \"fast\") @rebel {\n  name: String! @cost(value: \"FIELD\") @public\n}\n```\n\n### Argument \u0026amp; InputObject classes\n\nBase abstracts:\n\n```ruby\nclass BaseArgument \u003c GraphQL::Schema::Argument\n  include GraphQL::SchemaDirectives::Argument\nend\n\nclass BaseInputObject \u003c GraphQL::Schema::InputObject\n  include GraphQL::SchemaDirectives::InputObject\n  argument_class BaseArgument\nend\n```\n\nConcrete implementation:\n\n```ruby\nclass FormInput \u003c BaseInputObject\n  add_directive :oneField\n  argument :choice, String, required: true, directives: {\n    cost: { value: 'INPUT' },\n    public: nil\n  }\nend\n```\n\nPrints as:\n\n```graphql\ninput FormInput @oneField {\n  choice: String! @cost(value: \"INPUT\") @public\n}\n```\n\n### EnumValue \u0026amp; Enum classes\n\nBase abstracts:\n\n```ruby\nclass BaseEnumValue \u003c GraphQL::Schema::EnumValue\n  include GraphQL::SchemaDirectives::EnumValue\nend\n\nclass BaseEnum \u003c GraphQL::Schema::Enum\n  include GraphQL::SchemaDirectives::Enum\n  enum_value_class BaseEnumValue\nend\n```\n\nConcrete implementation:\n\n```ruby\nclass FormOption \u003c BaseEnum\n  add_directive :dunno\n  value 'GET', directives: { cost: { value: 'READ' }, public: nil }\n  value 'SET', directives: { cost: { value: 'WRITE' }, public: nil }\nend\n```\n\nPrints as:\n\n```graphql\nenum FormOption @dunno {\n  GET @cost(value: \"READ\") @public\n  SET @cost(value: \"WRITE\") @public\n}\n```\n\n### Other classes\n\nBase abstracts:\n\n```ruby\nclass BaseUnion \u003c GraphQL::Schema::Union\n  include GraphQL::SchemaDirectives::Union\nend\n\nclass BaseScalar \u003c GraphQL::Schema::Scalar\n  include GraphQL::SchemaDirectives::Scalar\nend\n```\n\n## Schema from type definitions\n\nYou may also [parse and print SDLs](https://graphql-ruby.org/schema/sdl.html) using the gem's `from_definition` method:\n\n```rb\nschema = GraphQL::SchemaDirectives.from_definition(type_defs)\nputs schema.print_schema_with_directives\n```\n\nThe local `from_definition` method accepts all the same options as [the underlying method](https://graphql-ruby.org/api-doc/1.11.6/GraphQL/Schema#from_definition-class_method). Calling `print_schema_with_directives` works exactly like the [default printer](https://graphql-ruby.org/api-doc/1.11.6/GraphQL/Language/Printer.html#print-instance_method) when operating on an unmodified document parse (elements with an original AST will print their schema directives natively).\n\nThis feature becomes useful when you start modifying a parsed document with class-based additions:\n\n```rb\nmodule Spaceship\n  include GraphQL::Schema::Interface\n  include GraphQL::SchemaDirectives::Interface\n  field :name, String, null: false, directives: { public: nil }\nend\n\ntype_defs = %(\n  type XWing {\n    name: String! @public\n  }\n  type Query {\n    ship: XWing\n  }\n  schema {\n    query: Query\n  }\n)\n\nschema = GraphQL::SchemaDirectives.from_definition(type_defs)\nschema.types['XWing'].implements(Spaceship)\nputs schema.print_schema_with_directives\n```\n\nUsing `print_schema_with_directives` will include directives from the original AST as well as directives applied to added classes.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgmac%2Fgraphql-ruby-schema-directives","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgmac%2Fgraphql-ruby-schema-directives","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgmac%2Fgraphql-ruby-schema-directives/lists"}