Closed Rohit-cheddr closed 8 years ago
Thanks for your question. If you're using external GraphQL server, you can set up Relay to send request directly to the server by putting the following code inside client/index.js
:
// client/index.js
Relay.injectNetworkLayer(
new Relay.DefaultNetworkLayer(config.externalUrl)
);
Moreover, you could also completely delete our internal GraphQL endpoint in the server/index.js
.
Gotcha! That's working. Thanks!
Gotcha! That's working. Thanks!
@Rohit-cheddr @lvarayut what happens to schema.json provided to babel-relay-plugin. Do we need to keep a copy of schema.js on the client and updateSchema locally?
Hi @nsuthar0914, I wouldn't keep a copy of schema.js
. I would, however, write a script to automatically generate the schema.json
from the external graphql server, here is an example of the script:
/* eslint-disable no-console */
import fetch from 'node-fetch';
import chalk from 'chalk';
import path from 'path';
import fs from 'fs';
async function fetchSchema(url) {
try {
const res = await fetch(url);
const schema = await res.json();
fs.writeFileSync(path.join(__dirname, '../data/schema.json'), JSON.stringify(schema, null, 4));
} catch (err) {
console.error(chalk.red(err.stack));
}
}
fetchSchema('http://your_endpont.com/graphql/schema');
@lvarayut -- is this supported by default on graphql? Or does the __schema
need to be added to the backend somehow?
I'm using a custom Laravel GraphQL implementation, as well as an implementation from graphcool (for learnrelay.com).
Thanks!
Hey @toobulkeh, not sure if I understand your question correctly, but normally, we don't need to manually manage the __schema
by ourselves.
Unfortunately your script above didn't work for me, as it couldn't verify the schema
This library worked well for me, as a starter script in package.json
:
"fetch": "./node_modules/.bin/fetch-graphql-schema https://api.graph.cool/relay/v1/asdj123kjas -o server/data/schema.json",
How could I go about connecting to an external graphql server in production? I can see in the development configuration that I just need to change the
proxy
to point to the external graphql url, but how would I do it in production? Here's what I have so far: