Questions tagged [graphql-ruby]

a Ruby implementation for GraphQL, a query language used for describing data requirements on complex application data models.

GraphQL is a query language created by Facebook for describing data requirements on complex application data models.

Website graphql-ruby.org

GitHub repository

143 questions
1
vote
1 answer

Get context inside a GraphQL schema

I'm using graphql-ruby and trying to protect admin's mutation in schema like that class MySchema < GraphQL::Schema mutation(Types::Admin::MutationType) if context[:current_user].admin? mutation(Types::MutationType) …
mzsrn
  • 41
  • 4
1
vote
2 answers

Graphql-ruby scoping in habtm, data leak in nested query

Here's an example of a data leak that occurs if using standard graphql-ruby setup. Using the graphql nested request below, the response returns data nested under company 1, that belongs to company 2. I expect the response to be limited to the the…
oma
  • 38,642
  • 11
  • 71
  • 99
1
vote
2 answers

How to avoid N+1 queries for has_many :through associations

I'm building a GraphQL API with Ruby on Rails and the graphql gem. Now I have some n:m relations, like Projects have many Users and Users have many Projects. My models are like: # /app/models/project.rb has_many :project_assignments has_many…
Slevin
  • 4,268
  • 12
  • 40
  • 90
1
vote
1 answer

passing arguments in graphQL queries

I'm just starting to learn GraphQL and I'm currently trying to create a clone of twitter. In the code below, is there a way I can pass the 81 from the id argument (e.g. user(id: 81)) automatically to the userId argument (e.g. tweets(userId:…
Jordanl
  • 13
  • 4
1
vote
1 answer

Should I order GraphQL results server side or client side?

We are using graphql-ruby in one of our internal projects: A Rails API backend serving a React Native Web frontend. I'm curious as to what is considered best practice in regard to handling ordering of returned results. One option I see is that we…
ianbayne
  • 43
  • 4
1
vote
0 answers

GraphQL ObjectType with Array field returning null

I have a field that is an array that I want to define in my resolver. The problem is, my result does not return the field which is an array, and just an object with null values. field :pies do type types[Types::OutputType] resolve ->…
Jeremy Lee
  • 43
  • 1
  • 5
1
vote
1 answer

Using resolvers to get more complex queries in GraphQL and Ruby

Trying to learn GraphQL in a Ruby on Rails API I am using the graphql gem. In this example, I have products and review, the product can have many reviews and review belongs to one product. Reviews have comment:string and stars:int. I have…
Greyhounddad
  • 115
  • 3
  • 9
1
vote
1 answer

GraphQL Ruby Using NameSpace

I am using graphql-ruby in my rails application. Currently, my app's directory structure looks like this. app - controllers - application_controller.rb - graphql_controller.rb - admin - application_controller.rb -…
K-Sato
  • 400
  • 7
  • 26
1
vote
0 answers

Rails + Graphql: How to optimize the sql query before graphqls schema is being executed on the result?

Field module Types class QueryType < GraphQL::Schema::Object field :restaurants, [RestaurantType], null: true do description "Lists all restaurants" end def restaurants Restaurant.all end end …
silicakes
  • 6,364
  • 3
  • 28
  • 39
1
vote
1 answer

Graphql complex boolean queries

I understand the principles of querying via graphql from the docs you could search: { "hero": { "name": "R2-D2" } } but how about you want to do something a bit more intricate such as: { "hero": { "name": "R2-D2 AND C-3PO AND BB-8 NOT…
JsonP
  • 67
  • 1
  • 10
1
vote
1 answer

graphql-ruby ObjectType vs Schema::Object

I'm in the process of writing Rspec tests for my GraphQL endpoints, and I noticed that the objects they use are of the type Schema::Object. I have been using ObjectType for my objects, which means I can't use MySchema.execute() to test. I've been…
jkost4
  • 73
  • 1
  • 8
1
vote
1 answer

How can I override the camelCase naming convention in graphql-ruby?

I'm using the excellent graphql-ruby gem (http://graphql-ruby.org/). I have a data structure that stores i18n strings essentially as hashes: {'en': 'Hello', 'es': 'Hola'}. Works great under normal circumstances. However, we just added simplified…
Luke Ehresman
  • 5,187
  • 1
  • 16
  • 20
1
vote
0 answers

Trying to get current_user in resolver

I have a use and project model. User has many projects. I am trying to understand Graphql. I am using knock gem to authenticate. I am passing current_user in context from the graphql controller. here is the code module Resolvers class Projects…
suyesh
  • 530
  • 7
  • 23
1
vote
1 answer

GraphQL cursor-based pagination converted into page or offset pagination

Our app uses Algolia for searching which allows for two typical forms of pagination: by page page=3&hitsPerPage=5 or by offset offset=10&length=5 GraphQL preferences cursor-based pagination where a recordID and length are provided…
Dan
  • 1,136
  • 10
  • 24
1
vote
0 answers

Properly structuring a GraphQL API that wraps different REST endpoints

this is my first post on stackoverflow (Long time reader). I mainly come from a Python background and am fairly new to Ruby. I'm wondering on what's the recommended way to structure a Ruby GraphQL API like the following. Each one of the keys has a…
nuka
  • 11
  • 1