howtographql / graphql-ruby Goto Github PK
View Code? Open in Web Editor NEWGraphQL Ruby example for How To GraphQL
Home Page: https://www.howtographql.com/graphql-ruby/0-introduction/
License: MIT License
GraphQL Ruby example for How To GraphQL
Home Page: https://www.howtographql.com/graphql-ruby/0-introduction/
License: MIT License
Hi,
ruby (2.5.1)
graphql (1.10.5, 1.10.3)
I'm currently having a problem with GraphQL::Types::ISO8601DateTime argument. For some reason I'm getting the error below when passing "2020-04-16" or other ISO8601 formatted strings.
Proxy Handler could not detect JSON: ***/gems/ruby-2.5.1/gems/graphql-1.10.5/lib/graphql/types/iso_8601_date_time.rb:35:in `coerce_result': undefined method `iso8601' for "2020-04-16T00:00:00.000Z":String (NoMethodError)
Any idea what's wrong?
Its not a Issue, its more like a question of how to graphql
Could you show me how to return the count of a given query with the query data?
Would be useful for pagination if the query return something like:
{
links: [20 links....]
total: 350
}
I'm not understanding how the resolver knows what type of data it returns and how to modifies it.
type types[Types::LinkType]
=> type [Types::LinkType]
Causes error when trying to query an allLinks filtered search
"error": {
"message": "Failed to build return type for Query.allLinks from #<GraphQL::Schema::List:0x00007fcce5b4d7f0 @of_type=Types::LinkType>: Unexpected type input: #<GraphQL::Schema::List:0x00007fcce5b4d7f0> (GraphQL::Schema::List)"
Correct defining of type can be seen in SearchObjectGraphQL README.md
I've following steps in tutorial page https://www.howtographql.com/graphql-ruby/7-filtering/ and after changing field :all_links, resolver: Resolvers::LinksSearch
in query_type.rb
got an error
TypeError: Cannot read property 'types' of undefined
at buildClientSchema (http://localhost:3000/assets/graphiql/rails/application.debug-3aff84d172cfc9d5cfec9289f9417ad7ee0ecdb1e7414d33c11cac078d02875e.js:34100:72)
at http://localhost:3000/assets/graphiql/rails/application.debug-3aff84d172cfc9d5cfec9289f9417ad7ee0ecdb1e7414d33c11cac078d02875e.js:2793:55
I've spent some time and found that issue is in link_search.rb
file.
After changing line type types[Types::LinkType]
to type [Types::LinkType]
(according to readme in https://github.com/rstankov/SearchObjectGraphQL) everything started working fine.
When connected via react-apollo (see #4) I can login and see links but search is broken, I see error: ApolloError.js:32 Uncaught (in promise) Error: GraphQL error: Variable searchText of type String! was provided invalid value
I was able to reproduce it in graphiql with:
query AllLinksSearchQuery($searchText: String!) {
allLinks(filter: {
OR: [
{url_contains: $searchText},
{description_contains: $searchText}
]
}) {
id
url
description
}
}
and query variables:
{
"$searchText": "Link"
}
I get error:
{
"errors": [
{
"message": "Variable searchText of type String! was provided invalid value",
"locations": [
{
"line": 1,
"column": 27
}
],
"value": null,
"problems": [
{
"path": [],
"explanation": "Expected value to not be null"
}
]
}
]
}
I was looking in the library, and it seems like any data sent with ISO8601DateTime is truncated to the nearest second when converted to a DateTime object under the hood. This is actually a bit of a problem because I need my data with milliseconds when sent in this format. Is there a way to do this?
I am getting this none descriptive error often when trying to create a user, I am able to figure out what the actual error is.
Error that graphql gives me:
{
"data": {
"createUser": null
},
"errors": [
{
"message": "Cannot return null for non-nullable field CreateUserPayload.user"
}
]
}
The actual error that I get in my resolver is usually related to devise password requirements.
user.errors.full_messages
=> ["Password is too short (minimum is 6 characters)"]
Here is my mutation:
class Mutations::CreateUser < Mutations::BaseMutation
argument :name, String, required: true
argument :email, String, required: true
argument :password, String, required: true
field :user, Types::UserType, null: false
field :email, String, null: false
field :password, String, null: false
field :errors, [String], null: false
def resolve(name:, email:, password:)
binding.pry
user = User.create({name: name, email: email, password: password})
user.persisted? ? { user: user, errors: [] } : { user: nil, errors: user.errors.full_messages }
end
end
I'd like to make this gem better and more useful. Anyone have any idea the best place look to get started on this fix ?
Hello,
Just writing to let you know that i tried to clone the project and make it run but was running on this error (Could not find rubocop-rails-0.4.1 in any of the sources) and i solved it by deleting the Gemfile.lock and running bundle install again.
I am running ruby 2.4.1 and rails 5.1.6.
I have configured howtographql/react-apollo with:
const networkInterface = createNetworkInterface({
uri: 'http://localhost:3000/graphql'
})
I have removed the subscriptions, issue #3
Anyway, to get the app to work I still had to do 2 things:
This definitely isn't high priority, but I'm currently unable to technically "complete" the graphql-ruby
tutorial. I suspect it's because all of the other tutorials have a multiple choice question at the end of each step, and I suspect those questions are used to track "progress." It seems like the graphql-ruby
tutorial doesn't have any of those multiple choice questions at the end of each step.
Hey, this might be a failure on my part - but from reading the guide on filtering with graphql https://www.howtographql.com/graphql-ruby/7-filtering/ the following screenshot is used:
But if I clone this repository, and apply the fix from #17, and run the same query I get:
I would have expected no links to be returned, as none of the descriptions contain example
.
Any help would be appreciated ๐
Maybe I'm missing something, but your Graphql controller has a bug in it. I made the mistake of copying it directly and wondered why variables weren't working.
graphql-ruby/app/controllers/graphql_controller.rb
def variables ensure_hash params[:validates] end
Shouldn't the param be ":variables"?
Related to rmosolgo/graphiql-rails#29
In https://www.howtographql.com/graphql-ruby/2-queries/ DateTimeType
is used in app/graphql/types/link_type.rb
but it's not defined yet.
The result is that when you open http://localhost:3000/graphiql
you get
SyntaxError: Unexpected token < in JSON at position 0
I got around the issue by copying date_time_type.rb with a minor adjustment to inherit from GraphQL::Schema::Scalar
instead of BaseScalar
Maybe the step to add date_time_type could be added to the tutorial?
Or a default type available in graphql 1.8.13 could be used instead?
Thanks for the great tutorial!
Hi,
Is there a way to set a default pagination ? For example, only the 20 first links ?
Thanks.
In the ruby tutorial, the mutation for creating a user looks like
class Resolvers::CreateUser < GraphQL::Function
AuthProviderInput = GraphQL::InputObjectType.define do
name 'AuthProviderSignupData'
argument :email, Types::AuthProviderEmailInput
end
argument :name, !types.String
argument :authProvider, !AuthProviderInput
type Types::UserType
def call(_obj, args, _ctx)
User.create!(
name: args[:name],
email: args[:authProvider][:email][:email],
password: args[:authProvider][:email][:password]
)
end
end
And creating a user looks like
mutation {
createUser(
name: "some_name",
authProvider: {
email: {
email: "[email protected]",
password: "1234"
}
}
) {
id
email
name
}
}
Since we are using the param email
twice, it is easy to mistype the json if you aren't C/P-ing.
New to this but maybe something like auth_input
?
I can PR this @RStankov
I followed all the steps until the end of the https://www.howtographql.com/graphql-ruby/2-queries/ and instead of seeing the documentation in the graphiql UI it will throw an error in the right panel of the graphiql:
TypeError: Cannot read property 'types' of undefined
at buildClientSchema (http://localhost:3000/assets/graphiql/rails/graphiql-0.12.0.self-84a2376c545f0620e86ec9d8681863a2f1b56b5eb3fe74c45003ff1fb982c1a3.js?body=1:33481:72)
at http://localhost:3000/assets/graphiql/rails/graphiql-0.12.0.self-84a2376c545f0620e86ec9d8681863a2f1b56b5eb3fe74c45003ff1fb982c1a3.js?body=1:2174:55
Any idea if I did something wrong or is there something in the tutorial that needs to be updated?
Add code/chapter like https://www.howtographql.com/graphql-js/9-subscriptions/
It was added in graphql-ruby 1.7 released September 18th
This will make graphql-ruby code compatible with https://github.com/howtographql/react-apollo/blob/master
I am finding documentation around testing a bit scarce.
What are some of the best practices for TDD and graphql?
Would you accept a PR for updating Rails to 6.0?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.