# Generated from wcc-contentful-graphql-1.0.0.gem by gem2rpm -*- rpm-spec -*- %global gem_name wcc-contentful-graphql Name: rubygem-%{gem_name} Version: 1.0.0 Release: 1%{?dist} Summary: [![Gem Version](https://badge.fury.io/rb/wcc-contentful-graphql.svg)](https://rubygems.org/gems/wcc-contentful-graphql) [![Build Status](https://travis-ci.org/watermarkchurch/wcc-contentful.svg?branch=master)](https://travis-ci.org/watermarkchurch/wcc-contentful) [![Coverage Status](https://coveralls.io/repos/github/watermarkchurch/wcc-contentful/badge.svg?branch=master)](https://coveralls.io/github/watermarkchurch/wcc-contentful?branch=master) # WCC::Contentful::Graphql This gem creates a GraphQL schema over your configured [data store](https://www.rubydoc.info/gems/wcc-contentful#Store_API). 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. ### Important note! 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](https://www.rubydoc.info/gems/wcc-contentful/WCC%2FContentful%2FConfiguration:store=) ## Usage Querying directly within your app ```rb schema = WCC::Contentful::Services.instance.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 => #{"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 ```rb 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 ``` ## Advanced Configuration ### Including your Contentful schema inside another GraphQL schema ```rb 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... ```gql 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 ... ``` ### Limiting the schema to only a few fields ```rb 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 ``` License: MIT URL: https://github.com/watermarkchurch/wcc-contentful/wcc-contentful-graphql Source0: https://rubygems.org/gems/%{gem_name}-%{version}.gem BuildRequires: ruby(release) BuildRequires: rubygems-devel BuildRequires: ruby >= 2.3 # BuildRequires: rubygem(coveralls) # BuildRequires: rubygem(dotenv) >= 2.2 # BuildRequires: rubygem(dotenv) < 3 # BuildRequires: rubygem(httplog) >= 1.0 # BuildRequires: rubygem(httplog) < 2 # BuildRequires: rubygem(rspec) >= 3.0 # BuildRequires: rubygem(rspec) < 4 # BuildRequires: rubygem(rspec_junit_formatter) >= 0.3.0 # BuildRequires: rubygem(rspec_junit_formatter) < 0.4 # BuildRequires: rubygem(rubocop) = 0.68 # BuildRequires: rubygem(simplecov) >= 0.16.1 # BuildRequires: rubygem(simplecov) < 0.17 # BuildRequires: rubygem(webmock) >= 3.0 # BuildRequires: rubygem(webmock) < 4 # BuildRequires: rubygem(guard) >= 2.14 # BuildRequires: rubygem(guard) < 3 # BuildRequires: rubygem(guard-rspec) >= 4.7 # BuildRequires: rubygem(guard-rspec) < 5 # BuildRequires: rubygem(guard-rubocop) >= 1.3.0 # BuildRequires: rubygem(guard-rubocop) < 1.4 # BuildRequires: rubygem(guard-shell) >= 0.7.1 # BuildRequires: rubygem(guard-shell) < 0.8 # BuildRequires: rubygem(generator_spec) >= 0.9.4 # BuildRequires: rubygem(generator_spec) < 0.10 # BuildRequires: rubygem(sqlite3) >= 1.3.6 # BuildRequires: rubygem(sqlite3) < 1.4 # BuildRequires: rubygem(timecop) >= 0.9.1 # BuildRequires: rubygem(timecop) < 0.10 BuildArch: noarch %description GraphQL interface over WCC::Contentful store. %package doc Summary: Documentation for %{name} Requires: %{name} = %{version}-%{release} BuildArch: noarch %description doc Documentation for %{name}. %prep %setup -q -n %{gem_name}-%{version} %build # Create the gem as gem install only works on a gem file gem build ../%{gem_name}-%{version}.gemspec # %%gem_install compiles any C extensions and installs the gem into ./%%gem_dir # by default, so that we can move it into the buildroot in %%install %gem_install %install mkdir -p %{buildroot}%{gem_dir} cp -a .%{gem_dir}/* \ %{buildroot}%{gem_dir}/ %check pushd .%{gem_instdir} # rspec spec popd %files %dir %{gem_instdir} %{gem_instdir}/Guardfile %{gem_libdir} %exclude %{gem_cache} %{gem_spec} %files doc %doc %{gem_docdir} %exclude %{gem_instdir}/.rspec %doc %{gem_instdir}/README.md %{gem_instdir}/Rakefile %doc %{gem_instdir}/doc %{gem_instdir}/wcc-contentful-graphql.gemspec %changelog * Thu Sep 16 2021 mockbuilder - 1.0.0-1 - Initial package