Skip to content

Commit

Permalink
Rewrite metaprogramming to support graphql 2.0.21 (#20)
Browse files Browse the repository at this point in the history
# Description ✍️

Rewrites graphoid metaprogramming schema generators to support the major
upgrades from graphql `1.x.x` ➡️ `2.x.x`. The tests rails app
was also updated with rails 7.0 and with support to ruby 3.2.2.

## Deprecations

#### ⚠️ include modules deprecations

`include Graphoiq::Queries` and `include Graphoid::Mutations` are not
supported anymore.
Now we should setup all generators in a initializer file following this
example:

```rb
# config/initializers/graphoid.rb
Rails.application.config.after_initialize do
  Graphoid.configure do |config|
    config.driver = :mongoid
  end

  Graphoid.initialize
  Graphoid::Types.initialize(User, House, Label, Snake, Value, Person, Account, Contract)
  Graphoid::Queries.generate(User, House, Label, Snake, Value, Person, Account, Contract)
  Graphoid::Mutations.generate(User, House, Label, Snake, Value, Person, Account, Contract)
end
```

#### ⚠️ Removed ActiveRecord support

#### ⚠️ Removed createMany, updateMany and deleteMany mutations

#### ⚠️ Removed filters inside belongs to and has_one nested
fields

```gql
{ users(where: { project: { ... } }) { id project { id } } 
```

#### ⚠️ Removed sort of nested fields

```gql
{ users(sort: { projects: { id: DESC } }) { id project { id } } 
```

### Quick test

```
cd spec/tester_mongo/
bundle install -j 5
rails s

# http://127.0.0.1:3000/graphiql
```

# roadmap

- [x] single query project { }
- [x] many query projects { }
- [x] where query projects(where: { }) { }
- [x] order query projects(order: { }) { }
- [x] create mutation createProject { }
- [x] update mutation updateProject { }
- [x] delete mutation deleteProject { }
- [x] query with nested fields single on result projects { example {
text } }
- [x] query with nested fields on result projects { examples { text } }
- [x] overcoming circular dependency on types (used string types
declaration)
- [x] query with nested fields on where projects(where: { example: {
text: "test" } }) { }
- [x] query with nested fields on result and where projects {
examples(where: ...) { text } }
- [x] query with some, none and every operators projects {
examples(where: { field_some: ...}) { text } }
- [x] Improve initialization and module enabling on models
- [x] enable graphields
- [x] enable graphorbid
- [x] tests
- [x] require all files upfront
- [ ] support Rails.appplication.eager_load!


# Working without crashes but no native eager load

```gql
{
  testField
  example {
    dateTime
    date
    time
    timestamp
    text
    bigInt
    decimal
    hashField
    array
  }
  project(where:{
    OR: [{nameIn: ["Test"]}]
  }) {
    id name createdAt updatedAt active

  }
  projects(order: { name: DESC}, where: { active: true}) {
    active
    name
    id
    createdAt
    updatedAt
  }
}


mutation m{
  createProject(data: {
    name: "Jhon"
  }) {
    id
    name
  }
}
```


## References

https://graphql-ruby.org/queries/ast_analysis.html
https://graphql-ruby.org/errors/error_handling

https://github.com/rmosolgo/graphql-ruby/issues?q=is%3Aissue+circular+loading

rmosolgo/graphql-ruby#2716 (comment)
https://guides.rubyonrails.org/active_model_basics.html#securepassword

# Tasks ☑️

- default rails new my_api --api
- rails generate graphql:install
- installing graphiql-rails in dev mode
- installing mongoid
- bootstrap graphoid
- generate scalars and initial mongoid driver
- hash scalar type
- fix comments
- add operators/attribute utils and grapho
- generate basic queries
- trying to process single query
- basic find queries is working
- fixing field not declared
- enable basic model filters
- make OR works
- enable in and nin filters
- plural queries is working but without eager load
- enabling sorting and filter on plural queries
- fixing and make works creates mutation
- add delete mutations
- add user model
- add nested resolve one to result queries
- add nested resolve many to result queries without filters
- update roadmap on readme
- enabling nested wheres
- enabling bi directional relationships
- fixing circular dependency with string type lazy declaration
- enable mutations and sorter type
- fixing circular dependency with string type lazy declaration
- implementign nesting wheres
- enabling graphield and fix operation with belongs to
- fix query operators contains, regex, lt and etc
- enable graphorbid
- simple tests
- tests passing
- tests passing
- add users with nested where tests
- add tests for create user mutation
- add tests for OR filters
- Add references to readme
- Reduce boilerplate to generate model queries and mutations
- Reduce boilerplate to generate model queries and mutations
- drop comments and remove xMeta support
- drop comments and remove xMeta support
- require all graphoid headers upfront
- Migrating app files to spec/dummy
- finalize migration to gem mode
- bringing original specs
- fix camelize operators
- fix delete one spec
- remove testes with create update delete many
- fix camelize and underscore fields
- fix camelize and underscore fields
- fix operations matches with underscore new format for graphql
- fix subqueries
- actions tests
- remove useless tests
- change order
- fix dummy app tests
- Enable input nested arguments
- fix camelcase for input arguments
- deprecating sub query on has_one and belongs to because only one
result is possible
- include some, none and every operators
- Fix tests on CI environemnts caused to to eager_load = true on rails
config
  • Loading branch information
niltonvasques authored Apr 23, 2023
1 parent cc6e15f commit 1db6c2c
Show file tree
Hide file tree
Showing 136 changed files with 1,475 additions and 1,861 deletions.
7 changes: 7 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# See https://git-scm.com/docs/gitattributes for more about git attribute files.

# Mark the database schema as having been generated.
db/schema.rb linguist-generated

# Mark any vendored files as having been vendored.
vendor/* linguist-vendored
24 changes: 14 additions & 10 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
runs-on: ubuntu-22.04
strategy:
matrix:
ruby: ['2.7.7', '2.7.8', '3.0.6']
ruby: ['2.7.7', '2.7.8', '3.0.6', '3.1.4', '3.2.2']
mongodb-version: ['4.2', '4.4', '5.0', '6.0']

steps:
Expand All @@ -34,20 +34,24 @@ jobs:
- name: Gems
id: gems
run: |
gem install bundler:2.4.10
gem install bundler:2.4.12
bundle install -j 5
- name: Tests Active Record
id: rspec-ar
run: |
DRIVER=ar bundle exec rspec
- name: Start MongoDB
uses: supercharge/[email protected]
with:
mongodb-version: ${{ matrix.mongodb-version }}

- name: Tests Active Mongoid
id: rspec-mongo
- name: Original Tests Mongoid Bundle
id: rspec-mongo-original-bundle
run: |
cd spec/tester_mongo
pwd
gem install bundler:2.4.12
bundle install -j 5
- name: Original Tests Mongoid
id: rspec-mongo-original
run: |
DRIVER=mongo bundle exec rspec
cd spec/tester_mongo
DRIVER=mongo rspec
37 changes: 34 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,34 @@
.byebug_history
graphoid-*.gem
coverage
# See https://help.github.com/articles/ignoring-files for more about ignoring files.
#
# If you find yourself ignoring temporary files generated by your text editor
# or operating system, you probably want to add a global ignore instead:
# git config --global core.excludesfile '~/.gitignore_global'

# Ignore bundler config.
/.bundle

# Ignore the default SQLite database.
/db/*.sqlite3
/db/*.sqlite3-*

# Ignore all logfiles and tempfiles.
/log/*
/tmp/*
!/log/.keep
!/tmp/.keep

# Ignore pidfiles, but keep the directory.
/tmp/pids/*
!/tmp/pids/
!/tmp/pids/.keep

# Ignore uploaded files in development.
/storage/*
!/storage/.keep
/tmp/storage/*
!/tmp/storage/
!/tmp/storage/.keep

# Ignore master key for decrypting credentials and more.
/config/master.key
*.gem
1 change: 1 addition & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--require spec_helper
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.0.6
ruby-3.2.2
19 changes: 0 additions & 19 deletions .travis.yml

This file was deleted.

37 changes: 15 additions & 22 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,31 +1,24 @@
# frozen_string_literal: true
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

source 'https://rubygems.org'
ruby '>= 2.7.0'
ruby ">= 2.7.0"

gemspec
# Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main"
gem 'activemodel'
gem 'actionpack'

#gem 'graphql', '~> 1.8.0'
gem 'graphql', git: 'https://github.com/oxeanbits/graphql-ruby.git', branch: 'ruby3-1.8.18'
gem "mongoid"

gem 'nokogiri', '~> 1.13.9'

gem 'activemodel', '>= 5.1'
gem 'actionpack', '>= 6.0.1'
# Use graphql gem for handle API
gem 'graphql', "~> 2.0.21"

group :development, :test do
gem 'byebug'
gem 'simplecov', require: false
gem 'pry-rails', '~> 0.3.4'

# Adds step-by-step debugging and stack navigation capabilities to pry using byebug.
gem 'pry-byebug'
gem "pry-byebug"
gem "rspec-rails"
end

group :test do
gem 'mongoid'
gem 'mongoid-rspec'
gem 'rspec'
gem 'rspec-rails', '>= 6.0'
gem 'sqlite3'
group :development do
# Speed up commands on slow machines / big apps [https://github.com/rails/spring]
# gem "spring"
end

Loading

0 comments on commit 1db6c2c

Please sign in to comment.