Coder Social home page Coder Social logo

howtographql / graphql-ruby Goto Github PK

View Code? Open in Web Editor NEW
264.0 5.0 61.0 132 KB

GraphQL Ruby example for How To GraphQL

Home Page: https://www.howtographql.com/graphql-ruby/0-introduction/

License: MIT License

Ruby 87.26% HTML 12.55% JavaScript 0.20%
graphql ruby graphql-server tutorial rails

graphql-ruby's Issues

Issue with GraphQL::Types::ISO8601DateTime

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?

Count on resolver

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.

Incorrect defining of type in links_search

type types[Types::LinkType]

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

TypeError: Cannot read property 'types' of undefined on tutorial https://www.howtographql.com/graphql-ruby/7-filtering/

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.

react-apollo AllLinksSearchQuery does not work

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"
        }
      ]
    }
  ]
}

iso8601 loses data

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?

"Cannot return null for non-nullable field CreateUserPayload.user"

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 ?

Connecting with howtographql/react-apollo

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:

  • add rack-cors - PR #5 (alternative is to set proxy on create-react-app package.json)
  • comment out protect_from_forgery (no idea how to fix it properly atm)

Can't technically "Complete" the tutorial

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.

graphql-ruby-tutorial-no-progress-checkmark

image

Graphql controller has incorrect variable name

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"?

DateTimeType undefined

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

graphql_error

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!

Default pagination

Hi,

Is there a way to set a default pagination ? For example, only the 20 first links ?

Thanks.

Confusing param :email

Problem

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.

Proposed solution

New to this but maybe something like auth_input ?

I can PR this @RStankov

TypeError: Cannot read property 'types' of undefined when completeing tutorial on https://www.howtographql.com/graphql-ruby/2-queries/

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?

Best practices for testing.

I am finding documentation around testing a bit scarce.

What are some of the best practices for TDD and graphql?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.