Skip to content

Commit

Permalink
Setup CI (#32)
Browse files Browse the repository at this point in the history
* Setup CI

* Setup CI

* Setup CI and prepare for release

* Setup CI and implement string support for ENUM input

* Setup CI

* Setup CI

* Setup CI

* Setup CI

* Setup CI

* Setup CI

* Setup CI

* Setup CI

* Setup CI

* Setup CI

* Setup CI

* Setup CI
  • Loading branch information
Carlos authored Aug 31, 2023
1 parent 7036aa3 commit 79ec655
Show file tree
Hide file tree
Showing 14 changed files with 154 additions and 68 deletions.
72 changes: 72 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: ci
concurrency:
group: "${{github.workflow}}-${{github.ref}}"
cancel-in-progress: true

on:
workflow_dispatch:
push:
branches:
- main
- v*.*.x
tags:
- v*.*.*
pull_request:
types: [opened, synchronize]
branches:
- '*'

jobs:
test:
name: "Run tests (${{ matrix.ruby }})"
runs-on: ubuntu-latest
env:
MYSQL_HOST: '127.0.0.1'
services:
mysql:
image: mysql:8.0
env:
MYSQL_HOST: ${{ env.MYSQL_HOST }}
MYSQL_ALLOW_EMPTY_PASSWORD: yes
MYSQL_ROOT_PASSWORD: ''
ports:
- "3306:3306"
options: >-
--health-cmd "mysqladmin ping"
--health-interval 5s
--health-timeout 2s
--health-retries 3
strategy:
fail-fast: false
matrix:
ruby: [2.7, 3.0, 3.1, 3.2]
steps:
- uses: actions/checkout@v3
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: false
- run: sudo apt-get install libsqlite3-dev -y
name: Setup Sqlite
- run: mysql -h 127.0.0.1 --port 3306 -u root -e 'CREATE DATABASE IF NOT EXISTS starwars;'
name: Create MySQL Database
- run: bundle install
- run: bundle exec rake compile
- run: bundle exec rake test
env:
GQL_MYSQL_HOST: ${{ env.MYSQL_HOST }}
GQL_MYSQL_PORT: ${{ job.services.mysql.ports[3306] }}

mac_compile:
name: "Compile for MacOS"
runs-on: macos-13
steps:
- uses: actions/checkout@v3
- uses: ruby/setup-ruby@v1
with:
ruby-version: '3.1'
bundler-cache: false
- run: gem install rake -v 13.0.6
- run: gem install rake-compiler -v 1.1.0
- run: gem install rake-compiler-dock -v 1.0.1
- run: CI_COMPILE=true rake compile
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
### Unreleased

### 1.0.0

* Allow ENUM inputs to receive string (needs to be enabled through config)
* Setup project's CI

### 1.0.0.rc2 - 2023-02-28

* Fixes for inputs
* Fixes for callbacks and field ownership
* Fixes for the inline type creator and sources
* Fixes to folder structure and constant management
* Provide a better URL for ISO 8601 specification
* Make some constants privat
* Make some constants private

### 1.0.0.rc1 - 2023-02-06

Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

72 changes: 20 additions & 52 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
<img src="./docs/assets/images/github.png" alt="Rails GraphQL - GraphQL meets RoR with the most Ruby-like DSL" />
</a>

![Gem Version](https://badge.fury.io/rb/rails-graphql.svg)
[![Gem Version](https://badge.fury.io/rb/rails-graphql.svg)](https://rubygems.org/gems/rails-graphql)
[![Tests](https://github.com/virtualshield/rails-graphql/actions/workflows/ci.yml/badge.svg)](https://github.com/virtualshield/rails-graphql/actions/workflows/ci.yml)
<!-- [![Code Climate](https://codeclimate.com/github/virtualshield/rails-graphql/badges/gpa.svg)](https://codeclimate.com/github/virtualshield/rails-graphql) -->
<!--([![Test Coverage](https://codeclimate.com/github/virtualshield/rails-graphql/badges/coverage.svg)](https://codeclimate.com/github/virtualshield/rails-graphql/coverage))-->
<!--([![Dependency Status](https://gemnasium.com/badges/github.com/virtualshield/rails-graphql.svg)](https://gemnasium.com/github.com/virtualshield/rails-graphql))-->
Expand Down Expand Up @@ -53,57 +54,24 @@ $ curl -d '{"query":"{ welcome }"}' \

# Features

[GraphQL Parser](https://rails-graphql.dev/guides/parser?utm_source=github)
: Supporting the <a href="https://spec.graphql.org/October2021/" target="_blank" rel="external nofollow">October 2021</a> spec

[Schemas](https://rails-graphql.dev/guides/schemas?utm_source=github)
: One or multiple under the same application or across multiple engines

[Queries](https://rails-graphql.dev/guides/queries?utm_source=github)
: 3 different ways to defined your queries, besides sources

[Mutations](https://rails-graphql.dev/guides/mutations?utm_source=github)
: 3 different ways to defined your mutations, besides sources

[Subscriptions](https://rails-graphql.dev/guides/subscriptions?utm_source=github)
: 3 different ways to defined your subscriptions, besides sources

[Directives](https://rails-graphql.dev/guides/directives?utm_source=github)
: 4 directives provided: `@deprecated`, `@skip`, `@include`, and `@specifiedBy`
: Event-driven interface to facilitate new directives

[Scalars](https://rails-graphql.dev/guides/scalars?utm_source=github)
: All the spec scalars plus: `any`, `bigint`, `binary`, `date`, `date_time`, `decimal`, `json`, and `time`

[Sources](https://rails-graphql.dev/guides/sources?utm_source=github)
: A bridge between classes and GraphQL types and fields
: Fully implemented for [ActiveRecord](https://rails-graphql.dev/guides/sources/active-record?utm_source=github) for `PostgreSQL`, `MySQL`, and `SQLite` databases.

[Generators](https://rails-graphql.dev/guides/generators?utm_source=github)
: Rails generators for you to get start quickly

[Shortcuts](https://rails-graphql.dev/guides/architecture#shortcuts?utm_source=github)
: Several shortcuts through `::GraphQL` module to access classes within the gem

[Type Map](https://rails-graphql.dev/guides/type-map?utm_source=github)
: A centralized place where all the types are stored and can be resolved

[Global ID](https://rails-graphql.dev/guides/global-id?utm_source=github)
: All objects defined supports `.to_global_id`, or simply `.to_gid`

[Subscriptions Provider](https://rails-graphql.dev/guides/subscriptions/providers?utm_source=github)
: Current supporting only [ActionCable](https://rails-graphql.dev/guides/subscriptions/action-cable-provider?utm_source=github) provider and [Memory](https://rails-graphql.dev/guides/subscriptions/memory-store?utm_source=github) store

[Introspection](https://rails-graphql.dev/guides/introspection?utm_source=github)
: All necessary types for introspection with proper descriptions
: Plain text display of the schemas

[Testing](https://rails-graphql.dev/guides/testing?utm_source=github)
: Support to validate GraphQL documents and stub values before requests

[Error Handling](https://rails-graphql.dev/guides/error-handling?utm_source=github)
: Full support to `rescue_from` within schemas
: A gracefully backtrace display
| Link | Description |
| --- | --- |
| [GraphQL Parser](https://rails-graphql.dev/guides/parser?utm_source=github) | Supporting the <a href="https://spec.graphql.org/October2021/" target="_blank" rel="external nofollow">October 2021</a> spec |
| [Schemas](https://rails-graphql.dev/guides/schemas?utm_source=github) | One or multiple under the same application or across multiple engines |
| [Queries](https://rails-graphql.dev/guides/queries?utm_source=github) | 3 different ways to defined your queries, besides sources |
| [Mutations](https://rails-graphql.dev/guides/mutations?utm_source=github) | 3 different ways to defined your mutations, besides sources |
| [Subscriptions](https://rails-graphql.dev/guides/subscriptions?utm_source=github) | 3 different ways to defined your subscriptions, besides sources |
| [Directives](https://rails-graphql.dev/guides/directives?utm_source=github) | 4 directives provided: `@deprecated`, `@skip`, `@include`, and `@specifiedBy`<br>Event-driven interface to facilitate new directives |
| [Scalars](https://rails-graphql.dev/guides/scalars?utm_source=github) | All the spec scalars plus: `any`, `bigint`, `binary`, `date`, `date_time`, `decimal`, `json`, and `time` |
| [Sources](https://rails-graphql.dev/guides/sources?utm_source=github) | A bridge between classes and GraphQL types and fields<br>Fully implemented for [ActiveRecord](https://rails-graphql.dev/guides/sources/active-record?utm_source=github) for `PostgreSQL`, `MySQL`, and `SQLite` databases |
| [Generators](https://rails-graphql.dev/guides/generators?utm_source=github) | Rails generators for you to get start quickly |
| [Shortcuts](https://rails-graphql.dev/guides/architecture#shortcuts?utm_source=github) | Several shortcuts through `::GraphQL` module to access classes within the gem |
| [Type Map](https://rails-graphql.dev/guides/type-map?utm_source=github) | A centralized place where all the types are stored and can be resolved |
| [Global ID](https://rails-graphql.dev/guides/global-id?utm_source=github) | All objects defined supports `.to_global_id`, or simply `.to_gid` |
| [Subscriptions Provider](https://rails-graphql.dev/guides/subscriptions/providers?utm_source=github) | Current supporting only [ActionCable](https://rails-graphql.dev/guides/subscriptions/action-cable-provider?utm_source=github) provider and [Memory](https://rails-graphql.dev/guides/subscriptions/memory-store?utm_source=github) store |
| [Introspection](https://rails-graphql.dev/guides/introspection?utm_source=github) | All necessary types for introspection with proper descriptions<br>Plain text display of the schemas |
| [Testing](https://rails-graphql.dev/guides/testing?utm_source=github) | Support to validate GraphQL documents and stub values before requests |
| [Error Handling](https://rails-graphql.dev/guides/error-handling?utm_source=github) | Full support to `rescue_from` within schemas<br>A gracefully backtrace display |

# How to contribute

Expand Down
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Rake tasks for development purposes

begin
require 'bundler/setup'
require 'bundler/setup' unless ENV.key?('CI_COMPILE')
rescue LoadError
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
end
Expand Down
6 changes: 0 additions & 6 deletions docs/_layouts/default.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@
</section>
</section>

{% if page.url == "/" %}
<section id="beta">
We are now in the RC2 (v1.0.0.rc2)! It's not recommended to be used in production <b>YET!</b>
</section>
{% endif %}

<div id="search-results" class="search-results"></div>
</header>

Expand Down
4 changes: 0 additions & 4 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ title: Getting Started
description: The basics about this gem and what you will find
---

{: .warning }
> **Important**
> We are now in the RC2 (v1.0.0.rc2)! It's not recommended to be used in production **YET!**
## Installation

{% include installation.md %}
Expand Down
10 changes: 10 additions & 0 deletions docs/handbook/settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,16 @@ different suffix, change this value to it.

----------------------------------------------------------------

#### `allow_string_as_enum_input`

Set if the server should allow strings be used as input for ENUM inputs.
It means that operations will support quotes for ENUM values embedded in
the documents.

**Default:** `false`

----------------------------------------------------------------

#### `enable_introspection`

Introspection is enabled by default. It is recommended to only use
Expand Down
5 changes: 5 additions & 0 deletions lib/rails/graphql/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ module GraphQL
# different suffix, change this value to it.
config.auto_suffix_input_objects = 'Input'

# Set if the server should allow strings be used as input for ENUM inputs.
# It means that operations will support quotes for ENUM values embedded in
# the documents (heredoc won't be accepted).
config.allow_string_as_enum_input = false

# Introspection is enabled by default. It is recommended to only use
# introspection during development and tests, never in production.
# This can also be set per schema level.
Expand Down
18 changes: 16 additions & 2 deletions lib/rails/graphql/type/enum.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ def indexed?
# Check if a given value is a valid non-deserialized input
def valid_input?(value)
(valid_token?(value, :enum) && all_values.include?(value.to_s)) ||
(value.is_a?(String) && all_values.include?(value))
(value.is_a?(String) && all_values.include?(value)) ||
(allow_string_input? && valid_token?(value, :string) &&
all_values.include?(value.to_s[1..-2]))
end

# Check if a given value is a valid non-serialized output
Expand All @@ -62,7 +64,13 @@ def as_json(value)

# Turn a user input of this given type into an ruby object
def deserialize(value)
new(value.is_a?(::GQLParser::Token) ? value.to_s : value) if valid_input?(value)
if valid_token?(value, :enum)
new(value.to_s)
elsif allow_string_input? && valid_token?(value, :string)
new(value[1..-2])
elsif valid_input?(value)
new(value)
end
end

# Use the instance as decorator
Expand Down Expand Up @@ -142,6 +150,12 @@ def inspect
#{inspect_directives}
INFO
end

private

def allow_string_input?
GraphQL.config.allow_string_as_enum_input
end
end

attr_reader :value
Expand Down
2 changes: 1 addition & 1 deletion lib/rails/graphql/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module VERSION
MAJOR = 1
MINOR = 0
TINY = 0
PRE = 'rc2'
PRE = nil

STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
end
Expand Down
15 changes: 15 additions & 0 deletions test/graphql/type/enum_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ def test_valid_input_ask
refute(DESCRIBED_CLASS.valid_input?(1))
refute(DESCRIBED_CLASS.valid_input?(nil))
refute(DESCRIBED_CLASS.valid_input?('abc'))

str_token = new_token('"A"', :string)
refute(DESCRIBED_CLASS.valid_input?(str_token))

stubbed_config(:allow_string_as_enum_input, true) do
assert(DESCRIBED_CLASS.valid_input?(str_token))
end
end

def test_valid_output_ask
Expand Down Expand Up @@ -58,6 +65,14 @@ def test_deserialize
test_value = DESCRIBED_CLASS.deserialize('A')
assert_instance_of(DESCRIBED_CLASS, test_value)
assert_equal('A', test_value.value)

str_token = new_token('"A"', :string)
assert_nil(DESCRIBED_CLASS.deserialize(str_token))
stubbed_config(:allow_string_as_enum_input, true) do
test_value = DESCRIBED_CLASS.deserialize(str_token)
assert_instance_of(DESCRIBED_CLASS, test_value)
assert_equal('A', test_value.value)
end
end

def test_decorate
Expand Down
1 change: 1 addition & 0 deletions test/integration/schemas/mysql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class MySQLRecord < ActiveRecord::Base
database: ENV.fetch('GQL_MYSQL_DATABASE', 'starwars'),
username: ENV.fetch('GQL_MYSQL_USERNAME', 'root'),
password: ENV['GQL_MYSQL_PASSWORD'],
port: ENV['GQL_MYSQL_PORT'],
)
end

Expand Down
6 changes: 6 additions & 0 deletions test/test_ext.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# Core ext methods

class Object < BasicObject
def new_token(value, type)
GQLParser::Token.new(value).tap do |token|
token.instance_variable_set(:@type, type)
end
end

def stub_ivar(name, value = nil)
instance_variable_set(name, value)
yield
Expand Down

0 comments on commit 79ec655

Please sign in to comment.