question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Use graphql extensions to provide information about bindings in server response

See original GitHub issue

There was a discussion a while ago about how to visualize the composition of a GraphQL server that uses multiple bindings. This proposal addresses this issue.

What information to provide

A ‘best practice’ GraphQL server uses a single schema, and using delegation in the resolvers to delegate queries and mutations to 1 or more bindings (back-end GraphQL endpoints). During development and testing, it would be great to know:

  • What binding(s) the different parts of a query response come from
  • Which connection settings where used for a binding

How to provide this information

The GraphQL spec allows extensions to be added to a server response. Tracing and cache control already use these extensions to provide additional information. I would propose to also use extension information to provide information about the bindings. A sample bindings extension object could look like this:

bindings: [
  { 
    "path": ["post, "comments"],
    "binding": {
      "name": "mydatasource",
      "endpoint": "http://api.graph.cool/mydatasource/dev"
    }
  }
]

The path specification is identical to the cache control extension (for a uniform approach). Endpoint information will not always be easily available though. Graphcool bindings provide an explicit endpoint. Generic bindings provide an executableSchema, so that information might not be available at all. One option might be creating an apollo-link variation that supports keeping track of this. Another, more generic solution, might be to setup an inline proxy to route all outgoing traffic through, so the hosts can be gathered (this is a commonly used setup in express).

How to visualize this information

This information could be used by graphql-playground to provide some form of visual representation. This can be discussed further in the graphql-playground repo.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
schicklingcommented, Dec 31, 2017

This is really awesome @kbrandwijk. Let’s see whether we can collaborate with the folks @apollographql on this, as this looks similar to the GraphQL tracing extension.

1reaction
kbrandwijkcommented, Dec 30, 2017

I’ve been playing around some more with this idea. This is what I’ve got so far:

  • Whenever you call a delegate in graphcool-binding, the path to the current node and the delegate that is called is saved on the context
  • A custom formatResponse function is used on apollo-server to access that information from the context, and put it in an extensions object.
  • The updated extension object looks something like:
bindings: [
  { 
    "path": ["post, "comments"],
    "binding": {
      "name": "mydatasource",
      "endpoint": "http://api.graph.cool/mydatasource/dev",
      "path": ["query", "comments"]
    }
  }
]
Read more comments on GitHub >

github_iconTop Results From Across the Web

Use graphql extensions to provide information about bindings ...
The GraphQL spec allows extensions to be added to a server response. Tracing and cache control already use these extensions to provide ......
Read more >
Fetching data with queries | Full-Stack Quickstart
This lets us use React Hooks to bind the results of GraphQL queries directly to our UI.
Read more >
GraphQL Code Libraries, Tools and Services
A query language for your API — GraphQL provides a complete description of the data in your API, gives clients the power to...
Read more >
GraphQL Server Basics: Demystifying the `info` Argument in ...
Another common use case where the info object can cause confusion is the implementation of a GraphQL server based on Prisma and prisma-binding....
Read more >
Spring for GraphQL Documentation
The main reason to use GraphQL over WebSocket is subscriptions which allow sending a stream of GraphQL responses, but it can also be...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found