Graphql-scalers Package and Federation 2 buildSubgraphSchema Error


Is there a compatibility issue with grapql-scalars and buildSubgraphSchema?
I’m getting an error when using DateTime:

TypeError: doc.definitions is not iterable (cannot read property undefined)
at concatAST (/Users/taranro/IdeaProjects/myweather/node_modules/graphql/utilities/concatAST.js:19:17)

Here’s the Apollo example with DateTime added:

import { ApolloServer } from '@apollo/server';
import { startStandaloneServer } from '@apollo/server/standalone';
import gql from 'graphql-tag';
import { buildSubgraphSchema } from '@apollo/subgraph';
import {resolvers as scalarResolvers, typeDefs as scalarTypeDefs} from "graphql-scalars";
import {typeDefs as myTypeDefs} from "./graphql/schema/weatherschema.js";
import {resolvers as myResolvers} from "./graphql/resolvers/weatherresolvers.js";

const typeDefs = gql`
  extend schema @link(url: "", import: ["@key", "@shareable"])

  type Query {
    me: User

  type User @key(fields: "id") {
    id: ID!
    username: String
    birthday: DateTime

const resolvers = {
    Query: {
        me() {
            return { id: '1', username: '@ava' };
    User: {
        __resolveReference(user, { fetchUserById }) {
            return fetchUserById(;

const allTypeDefs = [...scalarTypeDefs, typeDefs];
const allResolvers = {...scalarResolvers, ...resolvers};

const server = new ApolloServer({
    schema: buildSubgraphSchema({ allTypeDefs, allResolvers }),

const { url } = await startStandaloneServer(server);
console.log(`🚀  Server ready at ${url}`);

Getting when running:


TypeError: doc.definitions is not iterable (cannot read property undefined)
    at concatAST (/Users/taranro/IdeaProjects/myweather/node_modules/graphql/utilities/concatAST.js:19:17)
    at buildSubgraphSchema (/Users/IdeaProjects/myweather/node_modules/@apollo/subgraph/dist/buildSubgraphSchema.js:26:49)
    at file:///Users/IdeaProjects/myweather/i.js:40:13
    at (node:internal/modules/esm/module_job:193:25)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:530:24)
    at async loadESM (node:internal/process/esm_loader:91:5)
    at async handleMainPromise (node:internal/modules/run_main:65:12)

Node.js v18.12.1


The properties of the object passed to buildSubgraphSchema are named typeDefs and resolvers, so you probably mean

buildSubgraphSchema({ typeDefs: allTypeDefs, resolvers: allResolvers })

Though I’m not confident that you can pass an array for typeDefs. You might need to merge the type definitions some other way.

Hi Lenny,

Thanks for the response.
Can you provide more detail on the best way to merge schemas for buildSubGraphSchema()?
It would add a lot of value to the combined example in:

Implementing a subgraph with Apollo Server - Apollo GraphQL Docs

if you can show the Apollo recommended way to merge schemas from a very commonly used package package such as graphql-scalars with a user defined schema.


Lenny - sorry my bad. I assumed you are an Apollo employee! :zipper_mouth_face:

I am an Apollo Solutions Architect, but our recommendation for merging schemas in JS is to use Schema Merging – GraphQL Tools

Thanks, mergeTypeDefs from graphql-tools/merge worked:

import { mergeTypeDefs } from '@graphql-tools/merge';

const allResolvers = {...scalarResolvers, ...resolvers};
const mergedTypes = mergeTypeDefs([scalarTypeDefs, typeDefs]);

const server = new ApolloServer({
    schema: buildSubgraphSchema({typeDefs:mergedTypes, resolvers:allResolvers}),