Commit Graph

26 Commits

Author SHA1 Message Date
Javi Martín
629e208e9d Add and apply ArgumentAlignment rubocop rule
We're choosing the default `with_first_argument` style because it's the
one we use the most.
2023-08-18 14:56:16 +02:00
Finn Heemeyer
c984e666ff Add new GraphQL types, schema (with fields) & base mutation
The current consul GraphQL API has two problems.

1) It uses some unnecessary complicated magic to automatically create
   the GraphQL types and querys using an `api.yml` file. This approach
   is over-engineered, complex and has no benefits. It's just harder to
   understand the code for people which are not familiar with the
   project (like me, lol).

2) It uses a deprecated DSL [1] that is soon going to be removed from
   `graphql-ruby` completely. We are already seeing deprecation warning
   because of this (see References).

There was one problem. I wanted to create the API so that it is fully
backwards compatible with the old one, BUT the old one uses field names
which are directly derived from the ruby code, which results in
snake_case field names - not the GraphQL way. When I'm using the
graphql-ruby Class-based syntax, it automatically creates the fields in
camelCase, which breaks backwards-compatibility.

So I've added deprecated snake_case field names to keep it
backwards-compatible.

[1] https://graphql-ruby.org/schema/class_based_api.html
2022-06-01 11:41:09 +02:00
Javi Martín
6fd9a286d7 Don't access the database in after_initialize
Rails 5.2 crashes in the `db:create` task because it tries to run the
`after_initialize` block before the database is created.

The easiest way to solve it is to move the code out of the initializer
and calculate the API type definitions on demand. Note results are still
cached using a class instance variable (not to be confused with a class
variable), and so once definitions are obtained, they will remain
constant until the application is restarted, even in the development
environment.
2020-07-08 18:34:58 +02:00
Javi Martín
d0d681a44b Add and apply EmptyLineAfterGuardClause rule
We were inconsistent on this one. I consider it particularly useful when
a method starts with a `return` statement.

In other cases, we probably shouldn't have a guard rule in the middle of
a method in any case, but that's a different refactoring.
2019-10-24 17:56:03 +02:00
Juanjo Bazán
0063e7b4d8 Add feature flag for the GraphQL API 2019-10-20 14:52:07 +02:00
Julian Herrero
d24376f6ad Use double quotes in controllers/ 2019-03-13 22:19:49 +01:00
Julian Herrero
9a60135d9f [Consistency] remove semicolons from controllers 2019-01-08 15:46:46 +01:00
Bertocq
c9bc028524 Remove all unnecesary extra spacing and Layout/ExtraSpacing list from rubocop file 2017-06-28 14:12:51 +02:00
Alberto Miedes Garcés
18db68a430 Force pagination, limit query depth and complexity 2017-05-29 09:47:39 +02:00
Alberto Miedes Garcés
70a1dbde94 Fix bug when parsing query variables sent by the GraphiQL desktop client 2017-01-31 13:52:25 +01:00
Alberto Miedes Garcés
fd240b2fc7 Rescue all exceptions in production 2017-01-27 14:46:26 +01:00
Alberto Miedes Garcés
c52602e04b Simplify the way ApiTypesCreator is used 2017-01-27 13:13:19 +01:00
Alberto Miedes Garcés
620c83fb69 Simplify the way QueryTypeCreator is used 2017-01-27 12:54:33 +01:00
Alberto Miedes Garcés
ef6d089022 Refactor GraphqlController 2017-01-25 11:17:08 +01:00
Alberto Miedes Garcés
18fb1485eb No need to specify the resolve type for GraphQL::Schema
This was needed back in the 0.18.11 version but not anymore after the
update to 1.3.0
2017-01-16 11:28:28 +01:00
Alberto Miedes Garcés
232f5aa621 Parse GraphQL query variables to JSON
This is required after updating the gem to 1.3.0
2017-01-16 11:25:12 +01:00
Alberto Miedes Garcés
7a9373942a Testing GraphQL 1.3.0 in Travis 2017-01-12 20:11:47 +01:00
Alberto Miedes Garcés
2c5925f947 Refactor GraphqlController 2017-01-03 13:24:00 +01:00
Alberto Miedes Garcés
6013f84945 Handle multiple kind of requests in GraphQL controller
* Added support for GET requests
* Added support for application/graphql content-type for POST requests
* Handling query string parsing errors in controller
* Wrote specs for all this
2016-12-03 13:36:14 +01:00
Alberto Miedes Garcés
6fca1f02fe Added clarifying comments related to GraphQL return types 2016-11-17 17:23:57 +01:00
Alberto Miedes Garcés
f6cd7a3456 Disable CSRF protection for GraphQL controller
Related documentation at:
http://api.rubyonrails.org/classes/ActionController/RequestForgeryProtec
tion/ClassMethods.html
2016-11-13 20:07:09 +01:00
Alberto Miedes Garcés
dc62f6c914 Skip authorization check in GraphQL controller 2016-10-12 17:28:01 +02:00
Alberto Miedes Garcés
fe2546dbbb Added clarifying comments related to security 2016-10-01 08:50:16 +02:00
Alberto Miedes Garcés
eae18d9e37 Deleted useless debugging comment 2016-09-30 11:34:12 +02:00
Alberto Miedes Garcés
530da6b893 Implemented simple test query to proposals 2016-09-28 12:51:05 +02:00
Alberto Miedes Garcés
ab333d6627 Created controller and route to answer GraphQL queries 2016-09-28 12:47:07 +02:00