
Security News
Vite Releases Technical Preview of Rolldown-Vite, a Rust-Based Bundler
Vite releases Rolldown-Vite, a Rust-based bundler preview offering faster builds and lower memory usage as a drop-in replacement for Vite.
Easily toggle parts of a GraphQL schema on.
Add this line to your application's Gemfile:
gem 'graphql-preview'
And then execute:
$ bundle
Or install it yourself as:
$ gem install graphql-preview
The basic premise of this gem is to provide an easier interface to toggling parts of a GraphQL schema. You define a single class that contains all the definitions for how your toggler should behave, and this gem will handle the flipping for you.
The easiest use case to imagine for this gem is to think of something like a public API preview. Perhaps you want to be able to expose certain objects or fields if and only if a client provides a specific Accept
header. This gem will help you do that!
To get started, define a class that inherits from GraphQLPreview::SchemaModification
. This class can be given various properties, but the two most important are toggled_by
and toggled_on
:
class TestPreview < GraphQLPreview::SchemaModification
# A human-readable name of your preview
title "TestPreview"
# A description of your preview
description "Enable various library items"
# A symbol that uniquely identifies this preview -- explained below
toggled_by :enabled_library
# A date defining when this preview was announced, with an optional URL announcing it
announced_on Date.new(2017, 11, 1), url: "http://example.com"
# A date defining when this preview was updated, with an optional URL announcing it
updated_on Date.new(2017, 11, 2), url: "http://example.com"
# You can have more than one of these!
updated_on Date.new(2017, 11, 3), url: "http://example.com"
# The parts of your GraphQL schema you want toggled by this preview
toggled_on [
"Author", # an object
"ExtraInfo", # an interface,
"Author.socialSecurityNumber", # a field
"Book.author.includeMiddleInitial", # an argument
"Likeable", # a union,
"Cover", # an enum
"Cover.DIGITAL", # an enum value
"BookOrder", # an input object
"Mutation.addLike", # a mutation
]
end
This gem introduces a new method to apply on your schema, enabled_previews
. It takes an array,
and you should pass in the list of preview classes you want enabled on your schema. For example:
class Schema < GraphQL::Schema
query(query_type)
enabled_previews [
TestPreview
]
end
If you are using graphql-ruby
's .define
DSL a similar API is provided:
GraphQL::Schema.define do
query(query_type)
enabled_previews [
TestPreview
]
end
Schema.execute
After your preview class is configured, you'll need to make two minor changes to the way the schema is executed.
First, ensure that your context
object has a key called schema_previews
. Within this key, you'll provide an array of symbols that identify which previews you want enabled. For example:
context = { schema_previews: [:enabled_library] }
Next, simply pass in the GraphQLPreview::Mask
class to the except
kwarg.
Putting it all together, this looks like:
Schema.execute(query, context: context, except: GraphQLPreview::Mask)
It's up to you to decide how to determine the array in context[:schema_previews]
. It could be based on the Accept
header, some random Flipper
percentage, or anything else!
FAQs
Unknown package
We found that graphql-preview demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers 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
Vite releases Rolldown-Vite, a Rust-based bundler preview offering faster builds and lower memory usage as a drop-in replacement for Vite.
Research
Security News
A malicious npm typosquat uses remote commands to silently delete entire project directories after a single mistyped install.
Research
Security News
Malicious PyPI package semantic-types steals Solana private keys via transitive dependency installs using monkey patching and blockchain exfiltration.