Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for error extensions #24

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Commits on Dec 10, 2018

  1. Add support for error extensions

    This commit:
     - adds an ErrorExtensions attr to the graphErr type
     - adds an Extensions method to the graphErr type
    
    Why?
     - This adds support for error extensions as described in a
     recent(ish)  update to the [graphql
     spec](https://facebook.github.io/graphql/June2018/#example-fce18).
     The interface changes are minimally invasive, and are in fact
     invisible unless the importing code defines an interface that
     includes the `Extensions()` method.
    
    An example usage:
    
    ```go
    package foo
    
    import "github.com/machinebox/graphql"
    
    ...
    
    type extendedError interface {
    	Extensions() map[string]interface{}
    	Error() string
    }
    
    func bar() {
    ...
    
    	client := graphql.NewClient(...)
      ...
       err := c.client.Run(ctx, req, resp)
       if ok := err.(extendedError); ok {
    		extMsg, _ := json.Marshal(ee.Extensions())
        fmt.Println(extMsg)
        // prints out the extensions, e.g.:
        //{
        //  "message": "Name for character with ID 1002 could not be fetched.",
        //  "locations": [ { "line": 6, "column": 7 } ],
        //  "path": [ "hero", "heroFriends", 1, "name" ],
        //  "code": "CAN_NOT_FETCH_BY_ID",
        //  "timestamp": "Fri Feb 9 14:33:09 UTC 2018"
        //}
       }
    }
    
    ```
    blaedj committed Dec 10, 2018
    Configuration menu
    Copy the full SHA
    abf9ced View commit details
    Browse the repository at this point in the history