为Relay Modern设置GraphQL模拟服务器

时间:2017-06-12 20:15:07

标签: mocking graphql relay react-apollo

我正在尝试在Relay-Modern应用程序中从'gralphql-tools'设置GraphQL mockServer但是收到此错误:

parser.js:152 Uncaught 
GraphQLError {message: "Syntax Error GraphQL (1:1) Unexpected Name "data"↵…GVUeXBlIHsKICBVUAogIERPV04KICBDQU5DRUwKfQo=↵   ^↵", locations: Array(1), path: undefined, stack: "GraphQLError↵    at syntaxError (http://localhost:…tp://localhost:3000/static/js/bundle.js:33240:27)", nodes: undefined…}
locations
:
Array(1)
message
:
"Syntax Error GraphQL (1:1) Unexpected Name "data"↵↵1: 

我正在尝试使用relay-modern-hello-world http://graphql.org/blog/mocking-with-graphql/实现repo中概述的策略。

我基本上尝试替换fetchQuery()以将post请求替换为示例中包含的API:

function fetchQuery() {
    mockServer(schema, {
        Int: () => 6,
        Float: () => 22.1,
        String: () => 'Hello',
    });

    const appQuery = `
        query AppFeedQuery {
            feed (type: NEW, limit: 5) {
                ...Feed
            }
        }
    `;

    return mockServer.query(appQuery);
}

// Create a network layer from the fetch function
const network = Network.create(fetchQuery);

const source = new RecordSource();
const store = new Store(source);

我的尝试可以在https://github.com/sdee/relay-modern-hello-world

找到

我很欣赏任何想法。我是Relay和GraphQL的新手。谢谢!

0 个答案:

没有答案