Search code examples
reactjsrelayjsgraphql

"Teaching" the client what endpoint to use for graphql


I am adapting this to work within the context of a hapi server that also defines many other "conventional" api endpoints. If I want to define an endpoint for graphql (similar to the README) in this way:

route: {
  path: '/graphql',
  config: {}
}

...is there then additional configuration that needs to happen in the client side code to "teach" the react/relay app what path to make their post/get requests to?


Solution

  • As described in Relay Documentation. The endpoint your mentioned /graphql is what relay by default uses to communicate with graphql server. If you need to specify a different server and endpoint you would do:

    Relay.injectNetworkLayer(
      new Relay.DefaultNetworkLayer('http://example.com/graphql')
    )
    

    to modify Relay's default graphql endpoint and server.