dotansimha / graphql-code-generator

A tool for generating code based on a GraphQL schema and GraphQL operations (query/mutation/subscription), with flexible support for custom plugins.
https://the-guild.dev/graphql/codegen/
MIT License
10.79k stars 1.32k forks source link

✖ Syntax Error: Unexpected Name "import" during Loading GraphQL schemas #9529

Closed denniarems closed 1 year ago

denniarems commented 1 year ago

Which packages are impacted by your issue?

@graphql-codegen/cli, @graphql-codegen/client-preset

Describe the bug

While Loading the Schema by running graphql-codegen commend i'm getting ✖ Syntax Error: Unexpected Name "import".

Your Example Website or App

https://stackblitz.com/edit/nestjs-typescript-starter

Steps to Reproduce the Bug or Issue

Simply open the code, and the code will run automatically.

Expected behavior

as i dev i expect the graphql-codegen will execute successfully

Platform

Codegen Config File

// Importing the CodegenConfig type from '@graphql-codegen/cli' package
import type { CodegenConfig } from '@graphql-codegen/cli';

// Defining a configuration object for GraphQL code generator
const config: CodegenConfig = {
  // Array of schema configurations
  schema: [
    {
      // URL of the GraphQL endpoint
      //playground url : https://api.travelgatex.com/playground
      'https://api.travelgatex.com/': {
        // method: 'GET',
        // Headers to be sent with each request to this endpoint
        headers: {
          // Authorization header with API key
          Authorization: 'Apikey 8626355',
        },
      },
    },
  ],
  hooks: {
    afterAllFileWrite: ['eslint --fix'],
  },
  // Path to the directory containing GraphQL documents (queries, mutations, etc.)
  documents: './src/*.graphql',
  // Configuration for generated files
  generates: {
    // Path and filename for the output file
    './src/graphql-operations.ts': {
      // List of plugins to use during generation
      plugins: ['typescript', 'typescript-operations', 'typed-document-node'],
    },
  },
};

// Exporting the configuration object as default export
export default config;

Additional context

No response

saihaj commented 1 year ago

can you share how your ./src/graphql-operations.ts looks?