如何将现有GraphQLSchema对象传递给Apollo makeExecutableSchema函数

如何将现有GraphQLSchema对象传递给Apollo makeExecutableSchema函数,graphql,graphql-js,Graphql,Graphql Js,如何将现有的GraphQLSchema对象传递给makeExecutableSchema函数,以便与字符串定义的类型和解析器函数一起使用?在下面的类型定义中,我希望date属性是上述包中的GraphQLDate import { GraphQLDate, GraphQLTime, GraphQLDateTime } from 'graphql-iso-date'; let typeDefs = []; typeDefs.push(` type MyType { date: Date

如何将现有的GraphQLSchema对象传递给
makeExecutableSchema
函数,以便与字符串定义的类型和解析器函数一起使用?在下面的类型定义中,我希望
date
属性是上述包中的
GraphQLDate

import { GraphQLDate, GraphQLTime, GraphQLDateTime } from 'graphql-iso-date';

let typeDefs = [];
typeDefs.push(`
  type MyType {
    date: Date
  }
`);

let resolvers = {
  Query: () => { /* ... */ },
};

makeExecutableSchema({ typeDefs, resolvers });

事实证明,传递给
makeExecutableSchema
解析器
映射确实接受
GraphQLScalarType
,并且日期类型为标量。我们仍然需要手动将类型添加到
typeDefs
中,尽管

typeDefs.push('scalar Date');

所以我在我的项目中创建了一个外部标量模块,我正在做

import externalTypes from './externalTypes';
import printType from 'graphql';

// Define my typeDefs and resolvers here

for (let externalType of externalTypes) {
  let { name } = externalType;
  typeDefs.push(printType(externalType));
  resolvers[name] = externalType;
}

makeExecutableSchema({ typeDefs, resolvers });
我通过尝试/失败找到它,然后才在中找到它,因此发布。此外,我仍然不知道如何以这种方式添加非标量类型(除了手动编写其类型定义之外)

另外,
printType
函数从传递的类型对象打印模式定义,在这里变得很方便(有关更多详细信息,请参阅)

import externalTypes from './externalTypes';
import printType from 'graphql';

// Define my typeDefs and resolvers here

for (let externalType of externalTypes) {
  let { name } = externalType;
  typeDefs.push(printType(externalType));
  resolvers[name] = externalType;
}

makeExecutableSchema({ typeDefs, resolvers });