Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Modern] Error with .json schema #1639

Closed
adjourn opened this issue Apr 19, 2017 · 11 comments
Closed

[Modern] Error with .json schema #1639

adjourn opened this issue Apr 19, 2017 · 11 comments

Comments

@adjourn
Copy link

adjourn commented Apr 19, 2017

Docs:

The relay-compiler script 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.

Log:
> 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.
JSON file:
{
  "queryType": {
    "name": "Query"
  },
  "mutationType": {
    "name": "Mutation"
  },
  "subscriptionType": null,
  "types": [
    {
      "kind": "OBJECT",
      "name": "Query",
      "description": null,
      "fields": [

  // etc
@sibelius
Copy link
Contributor

you should use schema.graphql instead of schema.json

@adjourn
Copy link
Author

adjourn commented Apr 19, 2017

@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?

@sibelius
Copy link
Contributor

@sibelius
Copy link
Contributor

.json is used on Relay Classic

.graphql is used on Relay Modern

@leethree
Copy link

@unirey you can parse schema.json using buildClientSchema from graphql/utilities, and then print it using printSchema.

@sibelius
Copy link
Contributor

@leethree could you provide a code example of it?

@leethree
Copy link

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),
);

@adjourn adjourn closed this as completed Apr 19, 2017
@kassens kassens reopened this Apr 19, 2017
@kassens
Copy link
Member

kassens commented Apr 19, 2017

@leebyron: What's your intuition, should we just support .json everywhere in addition to .graphql?

@joho
Copy link

joho commented Apr 19, 2017

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 facebook/create-react-app#462 arrives, which gets less and less likely as I add extra build steps into the process.

@leebyron
Copy link
Contributor

It's easy for us to support both, so we should @kassens

@leebyron
Copy link
Contributor

Fwiw the Babel plugin supports both. This just seems like a small oversight in the compiler

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants