The
relay-compilerscript requires both the directory which holds your source files as well as a path to your GraphQL schema in either a .json or .graphql schema file.
> relay-compiler --src ./js --schema ./schema.json
HINT: pass --watch to keep watching for changes.
Parsed default in 0.04s
Writing default
Error: Error loading schema. Expected the schema to be a .graphql file using the
GraphQL schema definition language.
{
"queryType": {
"name": "Query"
},
"mutationType": {
"name": "Mutation"
},
"subscriptionType": null,
"types": [
{
"kind": "OBJECT",
"name": "Query",
"description": null,
"fields": [
// etc
you should use schema.graphql instead of schema.json
@sibelius
Im trying to find a way to convert it to .graphql (I get that particular schema from GraphQL endpoint) but nethertheless, the main question to authors is if .json an upcoming feature or are docs misleading?
.json is used on Relay Classic
.graphql is used on Relay Modern
@unirey you can parse schema.json using buildClientSchema from graphql/utilities, and then print it using printSchema.
@leethree could you provide a code example of it?
This should work:
import fs from 'fs';
import {
buildClientSchema,
printSchema,
} from 'graphql/utilities';
const schema = buildClientSchema(require('schema.json').data);
fs.writeFileSync(
`schema.graphql`,
printSchema(schema),
);
@leebyron: What's your intuition, should we just support .json everywhere in addition to .graphql?
FWIW I'd appreciate if both formats were supported.
I'm working with a graphql endpoint that currently only spits out the json form of the schema. I (now) understand there are workarounds, but I'm working on a react app that's currently ejected from create-react-app but I'd love to have a path back towards un-ejecting when https://github.com/facebookincubator/create-react-app/issues/462 arrives, which gets less and less likely as I add extra build steps into the process.
It's easy for us to support both, so we should @kassens
Fwiw the Babel plugin supports both. This just seems like a small oversight in the compiler
Most helpful comment
It's easy for us to support both, so we should @kassens