The server's `__typename` does not align with the graphql schema

After constructing a schema using type-graphql and setting up a server with apollo-server-lambda, then deploying to netlify functions, I encountered an issue.

The schema generated by type-graphql

# -----------------------------------------------
# !!! THIS FILE WAS GENERATED BY TYPE-GRAPHQL !!!
# !!!   DO NOT MODIFY THIS FILE BY YOURSELF   !!!
# -----------------------------------------------

type Project {
  name: String!
  summary: String!
  titleAndSummary: String!
}

type Query {
  projects: [Project!]!
}

Issue

When querying the API, I expected the response to be like this

{
  __schema {
    types {
      name
    }
  }
}

However, the actual response was different

{
    "data": {
        "__schema": {
            "types": [
                {
                    "name": "Query"
                },
                {
                    "name": "a"
                },
                // ...
            ]
        }
    }
}

I plan on utilizing graphql with Elm-Graphql, which auto-generates modules using their __typename property. This is why I need to address the above problem.

I have made several attempts to fix it but have not been able to pinpoint the source of the issue. It appears to be related to either type-graphql, apollo-server, or even netlify functions (I have tested both netlify dev server and real server deployments)

Code Samples

graphql.ts

import 'reflect-metadata';
import { ApolloServer } from 'apollo-server-lambda';
import { buildSchemaSync } from 'type-graphql';
import { QueryResolver, ProjectResolver } from './resolver';

const schema = buildSchemaSync({
  resolvers: [QueryResolver, ProjectResolver],
});

const server = new ApolloServer({
  schema,
  debug: false,
});

export const handler = server.createHandler();

types.ts

import { ObjectType, Field } from 'type-graphql';

@ObjectType()
export class Query {
  @Field((type) => [Project!]!)
  projects!: Project[];
}

@ObjectType()
export class Project {
  @Field((type) => String!)
  name!: string;

  @Field((type) => String!)
  summary!: string;
}

resolver.ts

import { Resolver, Query, FieldResolver, Root } from 'type-graphql';
import { Project } from './types';
import { projectList } from '../../db/fakeDB';

@Resolver()
export class QueryResolver {
  @Query((returns) => [Project])
  projects() {
    return projectList;
  }
}

@Resolver((of) => Project)
export class ProjectResolver {
  @FieldResolver((returns) => String!)
  titleAndSummary(@Root() project: Project) {
    return project.name + ' ++ ' + project.summary;
  }
}

Attempted Solution

We attempted to add __typename directly to the Object Type as shown below

 @Resolver((of) => Project)
export class ProjectResolver {
  @FieldResolver((returns) => String!)
  titleAndSummary(@Root() project: Project) {
    return project.name + ' ++ ' + project.summary;
  }

  @FieldResolver((returns) => String!)
  __typename() {
    return 'Project';
  }
}

Unfortunately, this resulted in an error during the request

◈ Error during invocation:  {
  errorMessage: 'Name "__typename" must not begin with "__", which is reserved by GraphQL introspection.',
  errorType: 'Error',
...

How can we resolve this issue?

English is not my native language, so I apologize for any mistakes. If you notice any corrections that need to be made, please let me know. Thank you.

Answer №1

It seems that bundle minification has been enabled, causing all the class names to be jumbled up.

Answer №2

During our observation of SST and TypeGraphQL in a production environment, we noticed that the "typename" attribute of ObjectType() and InputType() classes is being converted into abbreviated two-letter codes. Take a look at this photo for reference.

Michał, could you provide more details on how bundle minification works in TypeGraphQL and if there's a way to configure it to preserve the original class names used in the source code for ObjectType() and InputType() declarations?

"@serverless-stack/cli": "0.54.4",
"@serverless-stack/resources": "0.54.4",    
"apollo-server-lambda": "^2.21.1",
"type-graphql": "^1.1.1",

const server = new ApolloServer({
  schema: buildSchemaSync({
    resolvers: [getWebPaths],
    scalarsMap: [],
    validate: false,
  }),

  playground: true, //IS_LOCAL,
  introspection: true, // IS_LOCAL,

  context: async ({
    context,
    event,
  }: {
    event: APIGatewayEvent
    context: Context
  }): Promise<LambdaRoot> => {
    context.callbackWaitsForEmptyEventLoop = false

    return {
      event,
      context,
    }
  },
})

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Why does TypeScript struggle to recognize the properties of a type within a function parameter?

I am working with a `packages` object where I add items of the `Package` type ( See my code here and also Playground link), like this: type Callback = (obj: { source: string, types: string[], meta?: {} }) => void; interface Package { callback: ...

Mastering regular expressions in TypeScript

My goal is to perform linting on staged files that are either .ts or .tsx and located within the src folder. I am aware that for selecting all js files one can use "*.js": [--list of commands--] inside the lint staged property. I'm curious to learn m ...

Having trouble with retrieving data from the service as expected

To facilitate the transfer of data between components, I implemented a service: import { Injectable } from '@angular/core'; import { BehaviorSubject } from 'rxjs/BehaviorSubject'; @Injectable() export class DataTransferService { pr ...

Creating organized lists in Angular 4 using list separators

I'm struggling to organize a list with dividers between categories to group items accordingly. Each divider should be labeled with the month name, and the items under it should correspond to that specific month. My Goal: - August - item 1 - item ...

"Learn how to pass around shared state among reducers in React using hooks, all without the need for Redux

I've built a React hooks application in TypeScript that utilizes multiple reducers and the context API. My goal is to maintain a single error state across all reducers which can be managed through the errorReducer. The issue arises when I try to upd ...

The input elements fail to register the passed-in value until they are clicked on

I am experiencing an issue with my form element that contains a few input fields. Two of these inputs are set to readOnly and have values passed in from a calendar element. Even though the input elements contain valid dates, they still display an error mes ...

Issues with the File plugin in Ionic 2

Currently, I am working on integrating Quickblox into my Ionic2 application. I have successfully implemented all the required functionalities except for file uploading. In Quickblox, there is a specific function that needs to be used for uploading files, a ...

Meta fields in the Vue Router

Is it feasible to create custom properties while defining routes for VueRouter? Specifically, I am interested in setting up a route structure like the one below, where I can specify a component for an optional property "menu" for most routes in my applicat ...

How to create line breaks in Angular Material matTooltip elements?

I am currently utilizing Angular 7 along with Angular material matTooltip. My goal is to have the tooltip display each element on a separate line, similar to this: https://i.sstatic.net/faVoo.png However, I am encountering an issue where it displays thr ...

unable to retrieve the values of the rowdata in GridOption

ngOnInit(): void { this.fetchAllAnimeReviews(); } public fetchAllAnimeReviews(){ this.animeservice.getAllAnimeReviews() .subscribe( response => { this.Anime = response; this.gridOption = this.createGridO ...

Facing issues updating the parent state value while using NextJs with React

I recently started working with NextJS and React, and I'm using trpc along with useQuery to fetch a list of users. After fetching the user list, I need to filter it based on the user's name. Below is a snippet of the code I've been working ...

Uploading Files with Angular 2 using AJAX and Multipart Requests

I am currently working with Angular 2 and Spring MVC. At the moment, I have an Upload component that sends an AJAX request to the Spring backend and receives a response containing parsed data from a .csv file. export class UploadComponent { uploadFile: f ...

What is the best way to invoke a TypeScript function within an HTML document?

Can anyone guide me on how to import a TypeScript function into an HTML file and then call it? I'm a bit confused about the process. Below is my attempt in index.html to call the function getJSON() <!DOCTYPE html> <html lang="en"> < ...

Assistance with Troubleshooting a Complicated JavaScript/TypeScript Software

As someone new to the world of Javascript and Typescript, I am looking to gain a deeper understanding of how a specific large application runs through its steps. Can anyone suggest a debugger or other helpful tool for this task? ...

Customize the appearance of pages in Ionic 2 on the fly

In my app, there are 2 different themes based on the subject matter. However, some pages are shared between subjects. Therefore, I need to customize the ion-content based on the subject. I am looking for a solution to allow page-test to switch between dif ...

Exploring i18nNext integration with antd table in React

Presently, this is the UI https://i.stack.imgur.com/CMvle.png App.tsx import "./styles.css"; import MyTable from "./MyTable"; export default function App() { const data = [ { key: "1", date: "2022-01- ...

Defining the TypeScript interface for the onClick event in ReactJS

If you're looking to dive into React development, the tutorial on reactjs.org is a great place to start. While the tutorial code is in JavaScript, I've been working on converting it to TypeScript. I've successfully translated most of the c ...

Identify and monitor changes in every element within an array using Typescript/Angular 2

I am working with a person array that I have displayed in a Primeng datatable. Each object in the array has fields for first name, last name, and age, which are represented as columns in the table. Additionally, there is a column to display the status of e ...

What is the best way to mimic a library using SinonJs?

I am dealing with a file named browser-launcher.ts import * as Browser from "@lib/browser"; class BrowserLauncher { launch(options) { browser = Browser(options); } } export const browserLauncher = new BrowserLauncher() W ...

Wildcard routes taking precedence over other defined routes

Currently, I'm developing a Node.js server utilizing Express.js and Typescript. Within my project structure, there is a folder named "routes" where I store .ts files containing route definitions. An example of a route file might appear like this: impo ...