graphql-go / graphql

An implementation of GraphQL for Go / Golang
MIT License
9.86k stars 838 forks source link

GraphQL does not report parsing errors #597

Open drewwells opened 3 years ago

drewwells commented 3 years ago

I see this useless message reported in many situations: Cannot query field "{some field}" on type "RootQuery".

There's actual errors underneath that are not being reported. FieldsOnCorrectTypeRule is reporting graphql errors but none of these are surfaced to the caller.

gqlerrors.FormattedError{Message:"Oracle fields must be an object with field names as keys or a function which return such an object."

While these are server errors and not actionable by the client, they should at least be logged when encountered.

drewwells commented 3 years ago

The actual error was this

var oracleType = graphql.NewObject(graphql.ObjectConfig{                                       
    Name: "Oracle",
    Fields: &graphql.Fields{}
}

Error goes away when changed to this

var oracleType = graphql.NewObject(graphql.ObjectConfig{                                      
    Name: "Oracle",
    Fields: graphql.Fields{}
}
IFtech-A commented 3 years ago

I had an error similar to this. But it was caused by the name of the object. Works well

var UserType = graphql.NewObject(graphql.ObjectConfig{
    Name: "User",
    Fields: graphql.Fields{}
})

Does not work.

var UserType = graphql.NewObject(graphql.ObjectConfig{
    Name: "User type",
    Fields: graphql.Fields{}
})

Eventually, this type breaks the mutation in my case.

{
  "data": null,
  "errors": [
    {
      "message": "Cannot query field \"createUser\" on type \"RootMutation\".",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ]
    }
  ]
}