GraphQL schema will not import

I am trying to set up GraphQL express server. Following the tutorial, when I entered the following into the server boot, like this:

//   ENTIRE SCHEMA IN MAIN FILE  THIS WORKS!!!

...
var graphql = require('graphql');

const RootQuery = new graphql.GraphQLObjectType({
  name: 'RootQuery',
  description: 'The root query',
  fields: {
    viewer: {
      type: graphql.GraphQLString,
      resolve() {
        return 'viewer!';
      }
    }
  }
});

const Schema = new graphql.GraphQLSchema({
  query: RootQuery
});

app.use('/graphql', graphqlHTTP({ schema: Schema }));
...

It works by returning a data view! But since I don’t want everything in the main file, I tried to transfer this exact code to another file and import it as follows:

//THIS DOES NOT WORK
...
var Schema = require('./build/models/graphql/schema');
  app.use('/graphql', graphqlHTTP({ schema: Schema }));
...

I get the following error:

{
  "errors": [
    {
      "message": "Schema must be an instance of GraphQLSchema. Also ensure that there are not multiple versions of GraphQL installed in your node_modules directory."
    }
  ]
}

I'm not sure what I'm doing wrong. In case this has anything to do with it, I write in es6 and then throw it back to 5 in the build script. The schema file is built here:

// TRANSPILED SCHEMA

'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});

var graphql = require('graphql');

var RootQuery = new graphql.GraphQLObjectType({
  name: 'RootQuery',
  description: 'The root query',
  fields: {
    viewer: {
      type: graphql.GraphQLString,
      resolve: function resolve() {
        return 'viewer!';
      }
    }
  }
});

var Schema = new graphql.GraphQLSchema({
  query: RootQuery
});

exports.default = Schema;

And here is my .json package:

    "express": "^4.13.4",
    "express-graphql": "^0.5.3",
    "graphql": "^0.6.0",

, graphql node_modules. graphql ​​ INSTANCE , ? express-graphql ? ? node, ?

+4
3

, GraphQL, , JS. , :

var Schema = require ('./build/models/graphql/schema')

var Schema = new graphql.GraphQLSchema({ query: RootQuery });

export.default = ,

, . module.exports = Schema, Schema = require("./...").default

+4

, node_modules GraphQL.

, GraphQL node_modules. ? , , npm dedupe, npm 2. npm 3, , , graphql.

, , express-graphql graphql.

0

Graphql ( ), graphqly. Graphql:

import graphly from "graphqly";

const gBuilder = graphly.createBuilder();

// define types, inputs ... (in any order)
gBuilder.type("Products").implements("List").def(`
    products: [Product]!
`);

gBuilder.type("Product").def(`
    id: ID!
    name: String!
    link: String
    price: Int
`);

// we're too lazy to define a separate input, so we can `extend` other structure
gBuilder.input("ProductInput").ext("Product");

gBuilder.enum("ProductOrder").def(`
    PRICE_DESCENDING
    PRICE_ASCENDING
    NEWEST
`);
-1

All Articles