ошибка: ответ не выполнен: получен код состояния 400 "Graphql - PullRequest
0 голосов
/ 12 сентября 2018

что я хотел сделать, это отделить мою схему от файла index.js.так вот файл index.js и файл schema.js после разделения.

// schema.js

import { gql, makeExecutableSchema } from 'apollo-server-express';

const typeDefs = gql`
    type Query {
        hello : String
    }
`;

const resolvers = {
    Query:{
        hello: () => 'HelloWorld!'
    }
};

export default makeExecutableSchema({
    typeDefs,
    resolvers,
});

// index.js

import { ApolloServer } from 'apollo-server-express';
import express from 'express';

const schema = require('./schema');

const app = express();

const server = new ApolloServer({schema});
server.applyMiddleware({app});

app.listen(4000, ()=> {
    console.log(`app is working on port 4000 ${server.graphqlPath}`);
});

я все еще могу открыть площадку graphql на localhost: 4000 / graphql, но после разделения я получаю следующую ошибку.

enter image description here

1 Ответ

0 голосов
/ 12 сентября 2018

Я заменил строку const schema = require('./schema'); на import schema from './schema';, решил мою проблему.хотя я использую узел V8.10, я использовал компилятор babel для использования современного синтаксиса с узлом.старый синтаксис был проблемой.

...