罗孚正在谱写意想不到的超图
Rover is composing supergraph with unexpected character
我正在关注 docs 尝试启动 apollo 网关和 运行。我正在使用漫游者通过以下命令组成我的子图:rover supergraph compose --config ./supergraph-config.yaml > supergraph.graphql
该命令有效,但是当我尝试启动我的网关时,出现此错误:GraphQLError: Syntax Error: Unexpected character: U+FFFD.
supergraph compose 命令似乎出于某种原因添加了一些无效的字符。当我将文件打印为字符串时,我在文件顶部看到这两个字符:��.
示例:
��
schema
@link(url: "https://specs.apollo.dev/link/v1.0")
@link(url: "https://specs.apollo.dev/join/v0.2", for: EXECUTION)
{
query: Query
}
...
我也没有发现任何关于堆栈溢出或 github 的问题,所以我不太确定是什么问题。
网关:
const { ApolloServer, gql } = require('apollo-server');
const { ApolloGateway } = require('@apollo/gateway');
const { readFileSync } = require('fs');
const path = require("path");
const schemaString = readFileSync("../supergraph.graphql").toString()
const supergraphSdl = gql` ${schemaString} `;
// Initialize an ApolloGateway instance and pass it
// the supergraph schema
const gateway = new ApolloGateway({
supergraphSdl,
});
// Pass the ApolloGateway to the ApolloServer constructor
const server = new ApolloServer({
gateway,
});
server.listen().then(() => {
console.log(` Gateway ready `);
});
子图:
const { ApolloServer, gql } = require('apollo-server');
const { buildSubgraphSchema } = require('@apollo/subgraph');
interface User {
id: string
username: string
}
const typeDefs = gql`
extend schema
@link(url: "https://specs.apollo.dev/federation/v2.0",
import: ["@key", "@shareable"])
type Query {
me: User
}
type User @key(fields: "id") {
id: ID!
username: String
}
`;
const resolvers = {
Query: {
me() {
return { id: "1", username: "@ava" }
}
},
User: {
__resolveReference(user: User, { fetchUserById }: any){
return fetchUserById(user.id)
}
}
}
const server = new ApolloServer({
schema: buildSubgraphSchema({ typeDefs, resolvers })
});
server.listen(3000).then(({ url }) => {
console.log(` Server ready at ${url}`);
});
rover 生成的文件是用 utf16le 编码的,问题是我正在用 utf8 读取文件。
读取 'utf16le' 编码格式的文件有效。
const schemaString = await readFileSync('../supergraph.graphql', 'utf16le');
我正在关注 docs 尝试启动 apollo 网关和 运行。我正在使用漫游者通过以下命令组成我的子图:rover supergraph compose --config ./supergraph-config.yaml > supergraph.graphql
该命令有效,但是当我尝试启动我的网关时,出现此错误:GraphQLError: Syntax Error: Unexpected character: U+FFFD.
supergraph compose 命令似乎出于某种原因添加了一些无效的字符。当我将文件打印为字符串时,我在文件顶部看到这两个字符:��.
示例:
��
schema
@link(url: "https://specs.apollo.dev/link/v1.0")
@link(url: "https://specs.apollo.dev/join/v0.2", for: EXECUTION)
{
query: Query
}
...
我也没有发现任何关于堆栈溢出或 github 的问题,所以我不太确定是什么问题。
网关:
const { ApolloServer, gql } = require('apollo-server');
const { ApolloGateway } = require('@apollo/gateway');
const { readFileSync } = require('fs');
const path = require("path");
const schemaString = readFileSync("../supergraph.graphql").toString()
const supergraphSdl = gql` ${schemaString} `;
// Initialize an ApolloGateway instance and pass it
// the supergraph schema
const gateway = new ApolloGateway({
supergraphSdl,
});
// Pass the ApolloGateway to the ApolloServer constructor
const server = new ApolloServer({
gateway,
});
server.listen().then(() => {
console.log(` Gateway ready `);
});
子图:
const { ApolloServer, gql } = require('apollo-server');
const { buildSubgraphSchema } = require('@apollo/subgraph');
interface User {
id: string
username: string
}
const typeDefs = gql`
extend schema
@link(url: "https://specs.apollo.dev/federation/v2.0",
import: ["@key", "@shareable"])
type Query {
me: User
}
type User @key(fields: "id") {
id: ID!
username: String
}
`;
const resolvers = {
Query: {
me() {
return { id: "1", username: "@ava" }
}
},
User: {
__resolveReference(user: User, { fetchUserById }: any){
return fetchUserById(user.id)
}
}
}
const server = new ApolloServer({
schema: buildSubgraphSchema({ typeDefs, resolvers })
});
server.listen(3000).then(({ url }) => {
console.log(` Server ready at ${url}`);
});
rover 生成的文件是用 utf16le 编码的,问题是我正在用 utf8 读取文件。
读取 'utf16le' 编码格式的文件有效。
const schemaString = await readFileSync('../supergraph.graphql', 'utf16le');