
Security News
Astral Launches pyx: A Python-Native Package Registry
Astral unveils pyx, a Python-native package registry in beta, designed to speed installs, enhance security, and integrate deeply with uv.
wcc-contentful-graphql
Advanced tools
This gem creates a GraphQL schema over your configured data store. You can execute queries against this GraphQL schema to get all your contentful data. Under the hood, queries are executed against your backing store to resolve all the requested data.
The GraphQL schema currently does not utilize the "include" parameter, so it is
a very good idea to configure your store to either :eager_sync
or :lazy_sync
. If you don't do this, you will see a lot of requests to
Contentful for specific entries by ID as the GraphQL resolver walks all your links!
More info on configuration can be found here
Querying directly within your app
schema = WCC::Contentful::Services.instance.graphql_schema
=> #<GraphQL::Schema ...>
result = schema.execute(<<~QUERY)
{
allConference(filter: { code: { eq: "CLC2020" } }) {
title
startDate
code
}
}
QUERY
GET https://cdn.contentful.com/spaces/xxxxx/entries?content_type=conference&fields.code.en-US=CLC2020&locale=%2A
Status 200
=> #<GraphQL::Query::Result @query=... @to_h={"data"=>{"allConference"=>[{"title"=>"Church Leaders Conference", "startDate"=>"2020-04-28", "code"=>"CLC2020"}]}}>
result.to_h
=> {"data"=>
{"allConference"=>
[{"title"=>"Church Leaders Conference",
"startDate"=>"2020-04-28",
"code"=>"CLC2020"}]}}
Setting up a controller to respond to GraphQL queries
class Api::GraphqlController < Api::BaseController
include WCC::Contentful::ServiceAccessors
skip_before_action :authenticate_user!, only: :query
def query
result = graphql_schema.execute(
params[:query],
variables: params[:variables]
)
render json: result
end
end
QueryType = GraphQL::ObjectType.define do
# extend this to get 'schema_stitch'
extend WCC::Contentful::Graphql::Federation
name 'RootQuery'
field 'a', types.String
schema_stitch(WCC::Contentful::Services.instance.graphql_schema,
namespace: 'contentful')
end
Schema = GraphQL::Schema.define do
query QueryType
resolve_type ->(type, obj, ctx) {
raise StandardError, "Cannot resolve type #{type} #{obj.inspect} #{ctx.inspect}"
}
end
File.write('schema.gql', GraphQL::Schema::Printer.print_schema(Schema))
results in...
schema {
query: RootQuery
}
type Contentful {
"""
Find a Asset
"""
Asset(_content_type: Contentful_StringQueryOperatorInput, description: Contentful_StringQueryOperatorInput, id: ID, title: Contentful_StringQueryOperatorInput): Contentful_Asset
"""
Find a CallToAction
"""
CallToAction(_content_type: Contentful_StringQueryOperatorInput, id: ID, internalTitle: Contentful_StringQueryOperatorInput, style: Contentful_StringQueryOperatorInput, text: Contentful_StringQueryOperatorInput, title: Contentful_StringQueryOperatorInput): Contentful_CallToAction
...
store = WCC::Contentful::Services.instance.store
builder =
WCC::Contentful::Graphql::Builder.new(
WCC::Contentful.types,
store,
).configure do
root_types.slice!('conference')
schema_types['conference'].define do
# change the types of some fields, undefine fields, etc...
end
end
@schema = builder.build_schema
FAQs
Unknown package
We found that wcc-contentful-graphql demonstrated a not healthy version release cadence and project activity because the last version was released 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
Astral unveils pyx, a Python-native package registry in beta, designed to speed installs, enhance security, and integrate deeply with uv.
Security News
The Latio podcast explores how static and runtime reachability help teams prioritize exploitable vulnerabilities and streamline AppSec workflows.
Security News
The latest Opengrep releases add Apex scanning, precision rule tuning, and performance gains for open source static code analysis.