score:0

it takes a little extra work. basically you have to dump a serialized version of the schema to a file on the server side, and then move that file over to the client and include it during babel compilation. facebook has a babel plugin that takes this file and builds it into the bundle in order for relay to know about the schema.

edit: here is a snippet for how to dump the schema file to json

import { graphql }  from 'graphql'
import { introspectionquery, printschema } from 'graphql/utilities'

/*
  generates json of our schema for use by relay
 */
export default function (schema) {
  return new promise((resolve, reject) => {
    graphql(schema, introspectionquery).then(result => {
      if (result.errors) {
        console.error(`error introspecting schema: ${result.errors}`)
        reject(new error(result.errors))
      } else {
        resolve({ json: result, graphql: printschema(schema) })
      }
    })
  })
}

after you obtain that, you have to npm install babel-relay-plugin and include that in your babel plugins (probably in the webpack config, if you're using that).


Related Query

More Query from same tag