
Security News
CISA’s 2025 SBOM Guidance Adds Hashes, Licenses, Tool Metadata, and Context
CISA’s 2025 draft SBOM guidance adds new fields like hashes, licenses, and tool metadata to make software inventories more actionable.
graphql_relay_identifier
Advanced tools
This gem provides an implementation the Relay Global Object Identification specification in Ruby, ensuring compatibility with GraphQL Federation. It allows you to define and resolve global identifiers for your GraphQL objects, making it easier to work with Relay and GraphQL Federation in your applications.
Add this line to your application's Gemfile
:
gem 'graphql_relay_identifier', require: 'graphql/relay/identifier/global_object_identifier'
And then execute:
bundle install
If bundler is not being used to manage dependencies, install the gem by executing:
gem install graphql_relay_identifier
Update your schema to overide the id_from_object
and object_from_id
methods and use the
GraphQL::Relay::Identifier::GlobalObjectIdentifier
module to handle global identifiers.
class ApplicationSchema < GraphQL::Schema
# ... other configuration
def self.id_from_object(object, type, _query_ctx)
GraphQL::Relay::Identifier::GlobalObjectIdentifier.to_relay_id(object, type)
end
def self.object_from_id(node_id, _query_ctx)
GraphQL::Relay::Identifier::GlobalObjectIdentifier.from_relay_id(node_id)
end
end
RECOMMENDED: Set the GraphQL::Schema::UniqueWithinType.default_id_separator
to a :
(colon).
This is used to deliminate the GraphQL type name from the identifier fields in the global object
identifier.
# config/initializers/graphql.rb
GraphQL::Schema::UniqueWithinType.default_id_separator = ':'
ADVANCED CONFIGURATION: Introduce an initializer to set up any custom identifier configurations for your models and types, as needed.
NOTE: This is only necessary if you have models that do not use the default id
field as their
primary key.
# config/initializers/graphql_relay_identifier.rb
GraphQL::Relay::Identifier::GlobalObjectIdentifier.add_identifier 'BlogPost', :slug
GraphQL::Relay::Identifier::GlobalObjectIdentifier.add_identifier 'ModelWithComplexKey', :field1, :field2,
GraphQL::Relay::Identifier::GlobalObjectIdentifier.add_identifier 'ModelWithVirtualAttribute', :id, virtual_attribute_names: %i[some_virtual_attribute]
GraphQL::Relay::Identifier::GlobalObjectIdentifier.add_identifier
This method allows you to define a global identifier for a specific model when the default (id
) is
not suitable.
You can specify one or more fields to be used as the identifier, and optionally, you can define virtual attributes that should be included in the identifier. Virtual attributes are not persisted in the database but play a role in how a model instance behaves and is identified.
Suppose you have a model BlogPost
with a slug
field that is used as the primary key for the
model. Assuming the GraphQL Type for this model is BlogPost
, the identifier for a specific
instance of this model with a slug
value of my-awesome-blog-post
would be represented as:
Base64.strict_encode64('BlogPost:{"v":1,"klass":"BlogPost","slug":"my-awesome-blog-post"}')
This identifier can be used in GraphQL queries to uniquely identify the BlogPost
instance with:
BlogPost
slug
with the unique value my-awesome-blog-post
After checking out the repo, run bin/setup
to install dependencies. Then, run rake spec
to run
the tests. You can also run bin/console
for an interactive prompt that will allow you to
experiment.
To install this gem onto your local machine, run bundle exec rake install
. To release a new
version, update the version number in version.rb
, and then run bundle exec rake release
, which
will create a git tag for the version, push git commits and the created tag, and push the .gem
file to rubygems.org.
Bug reports and pull requests are welcome on GitHub at https://github.com/mjfaga/graphql_relay_identifier. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.
The gem is available as open source under the terms of the MIT License.
Everyone interacting in the GraphQL::Relay::Identifier project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.
FAQs
Unknown package
We found that graphql_relay_identifier demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CISA’s 2025 draft SBOM guidance adds new fields like hashes, licenses, and tool metadata to make software inventories more actionable.
Security News
A clarification on our recent research investigating 60 malicious Ruby gems.
Security News
ESLint now supports parallel linting with a new --concurrency flag, delivering major speed gains and closing a 10-year-old feature request.