diff --git a/.eslintrc b/.eslintrc index 07cbe76b6..e5747c625 100644 --- a/.eslintrc +++ b/.eslintrc @@ -11,7 +11,6 @@ "./tsconfig.json", "./benchmarks/tsconfig.json", "./examples/tsconfig.json", - "./examples/esm/tsconfig.json", "./scripts/tsconfig.json", "./tests/tsconfig.json" ] @@ -27,7 +26,6 @@ "./tsconfig.json", "./benchmarks/tsconfig.json", "./examples/tsconfig.json", - "./examples/esm/tsconfig.json", "./scripts/tsconfig.json", "./tests/tsconfig.json" ] diff --git a/.vscode/launch.json b/.vscode/launch.json index 8b724e6a5..0d52caf47 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -27,7 +27,6 @@ "automatic-validation", "custom-validation", "enums-and-unions", - // "esm", -- does not work with `ts-node/register` "extensions", "generic-types", "graphql-scalars", diff --git a/docs/examples.md b/docs/examples.md index db548cfb1..4ea50125b 100644 --- a/docs/examples.md +++ b/docs/examples.md @@ -12,7 +12,6 @@ Each subdirectory contains a `examples.graphql` file with predefined GraphQL que ## Basics - [Simple usage of fields, basic types and resolvers](https://github.com/MichalLytek/type-graphql/tree/master/examples/simple-usage) -- [ECMAScript modules (ESM)](https://github.com/MichalLytek/type-graphql/tree/master/examples/esm) ## Advanced diff --git a/examples/README.md b/examples/README.md index ef03c4be3..7d5e6638f 100644 --- a/examples/README.md +++ b/examples/README.md @@ -12,7 +12,6 @@ Each subdirectory contains a `examples.graphql` file with predefined GraphQL que ## Basics - [Simple usage of fields, basic types and resolvers](./simple-usage) -- [ECMAScript modules (ESM)](./esm) ## Advanced diff --git a/examples/esm/.eslintrc b/examples/esm/.eslintrc deleted file mode 100644 index bd6f0a2f0..000000000 --- a/examples/esm/.eslintrc +++ /dev/null @@ -1,11 +0,0 @@ -{ - "rules": { - "import/no-extraneous-dependencies": [ - "error", - { - "devDependencies": true, - "packageDir": ["./", "./examples/esm"] - } - ] - } -} diff --git a/examples/esm/examples.graphql b/examples/esm/examples.graphql deleted file mode 100644 index 35edc9e98..000000000 --- a/examples/esm/examples.graphql +++ /dev/null @@ -1,25 +0,0 @@ -query GetRecipe1 { - recipe(title: "Recipe 1") { - title - description - ratings - creationDate - ratingsCount(minRate: 2) - averageRating - } -} - -query GetRecipes { - recipes { - title - description - creationDate - averageRating - } -} - -mutation AddRecipe { - addRecipe(recipe: { title: "New recipe", description: "Simple description" }) { - creationDate - } -} diff --git a/examples/esm/index.ts b/examples/esm/index.ts deleted file mode 100644 index 725c75d01..000000000 --- a/examples/esm/index.ts +++ /dev/null @@ -1,22 +0,0 @@ -import "reflect-metadata"; -import path from "node:path"; -import url from "node:url"; -import { ApolloServer } from "@apollo/server"; -import { startStandaloneServer } from "@apollo/server/standalone"; -import { buildSchema } from "type-graphql"; -import { RecipeResolver } from "./recipe.resolver.js"; - -// Build TypeGraphQL executable schema -const schema = await buildSchema({ - // Array of resolvers - resolvers: [RecipeResolver], - // Create 'schema.graphql' file with schema definition in current directory - emitSchemaFile: path.resolve(path.dirname(url.fileURLToPath(import.meta.url)), "schema.graphql"), -}); - -// Create GraphQL server -const server = new ApolloServer({ schema }); - -// Start server -const { url: serverURL } = await startStandaloneServer(server, { listen: { port: 4000 } }); -console.log(`GraphQL server ready at ${serverURL}`); diff --git a/examples/esm/package.json b/examples/esm/package.json deleted file mode 100644 index 3fd09c542..000000000 --- a/examples/esm/package.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "type": "module", - "//": "FIXME: 'type-graphql' as dependency to avoid ESLint error", - "dependencies": { - "type-graphql": "file:../.." - } -} diff --git a/examples/esm/recipe.data.ts b/examples/esm/recipe.data.ts deleted file mode 100644 index 53681d4cd..000000000 --- a/examples/esm/recipe.data.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { Recipe } from "./recipe.type.js"; - -function createRecipe(recipeData: Partial) { - return Object.assign(new Recipe(), recipeData); -} - -export function createRecipeSamples() { - return [ - createRecipe({ - description: "Desc 1", - title: "Recipe 1", - ratings: [0, 3, 1], - creationDate: new Date("2018-04-11"), - }), - createRecipe({ - description: "Desc 2", - title: "Recipe 2", - ratings: [4, 2, 3, 1], - creationDate: new Date("2018-04-15"), - }), - createRecipe({ - description: "Desc 3", - title: "Recipe 3", - ratings: [5, 4], - creationDate: new Date(), - }), - ]; -} diff --git a/examples/esm/recipe.input.ts b/examples/esm/recipe.input.ts deleted file mode 100644 index 971691562..000000000 --- a/examples/esm/recipe.input.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { Field, InputType } from "type-graphql"; -import type { Recipe } from "./recipe.type.js"; - -@InputType() -export class RecipeInput implements Partial { - @Field() - title!: string; - - @Field({ nullable: true }) - description?: string; -} diff --git a/examples/esm/recipe.resolver.ts b/examples/esm/recipe.resolver.ts deleted file mode 100644 index 92821b36b..000000000 --- a/examples/esm/recipe.resolver.ts +++ /dev/null @@ -1,41 +0,0 @@ -import type { ResolverInterface } from "type-graphql"; -import { Arg, FieldResolver, Int, Mutation, Query, Resolver, Root } from "type-graphql"; -import { createRecipeSamples } from "./recipe.data.js"; -import { RecipeInput } from "./recipe.input.js"; -import { Recipe } from "./recipe.type.js"; - -@Resolver(_of => Recipe) -export class RecipeResolver implements ResolverInterface { - private readonly items: Recipe[] = createRecipeSamples(); - - @Query(_returns => Recipe, { nullable: true }) - async recipe(@Arg("title") title: string): Promise { - return this.items.find(recipe => recipe.title === title); - } - - @Query(_returns => [Recipe], { description: "Get all the recipes from around the world " }) - async recipes(): Promise { - return this.items; - } - - @Mutation(_returns => Recipe) - async addRecipe(@Arg("recipe") recipeInput: RecipeInput): Promise { - const recipe = Object.assign(new Recipe(), { - description: recipeInput.description, - title: recipeInput.title, - ratings: [], - creationDate: new Date(), - }); - await this.items.push(recipe); - - return recipe; - } - - @FieldResolver() - ratingsCount( - @Root() recipe: Recipe, - @Arg("minRate", _type => Int, { defaultValue: 0 }) minRate: number, - ): number { - return recipe.ratings.filter(rating => rating >= minRate).length; - } -} diff --git a/examples/esm/recipe.type.ts b/examples/esm/recipe.type.ts deleted file mode 100644 index a9b265d65..000000000 --- a/examples/esm/recipe.type.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { Field, Float, Int, ObjectType } from "type-graphql"; - -@ObjectType({ description: "Object representing cooking recipe" }) -export class Recipe { - @Field() - title!: string; - - @Field(_type => String, { nullable: true, deprecationReason: "Use 'description' field instead" }) - get specification(): string | undefined { - return this.description; - } - - @Field({ nullable: true, description: "The recipe description with preparation info" }) - description?: string; - - @Field(_type => [Int]) - ratings!: number[]; - - @Field() - creationDate!: Date; - - @Field(_type => Int) - ratingsCount!: number; - - @Field(_type => Float, { nullable: true }) - get averageRating(): number | null { - const ratingsCount = this.ratings.length; - if (ratingsCount === 0) { - return null; - } - const ratingsSum = this.ratings.reduce((a, b) => a + b, 0); - - return ratingsSum / ratingsCount; - } -} diff --git a/examples/esm/schema.graphql b/examples/esm/schema.graphql deleted file mode 100644 index ef1662b16..000000000 --- a/examples/esm/schema.graphql +++ /dev/null @@ -1,44 +0,0 @@ -# ----------------------------------------------- -# !!! THIS FILE WAS GENERATED BY TYPE-GRAPHQL !!! -# !!! DO NOT MODIFY THIS FILE BY YOURSELF !!! -# ----------------------------------------------- - -""" -The javascript `Date` as string. Type represents date and time as the ISO Date string. -""" -scalar DateTime - -type Mutation { - addRecipe(recipe: RecipeInput!): Recipe! -} - -type Query { - recipe(title: String!): Recipe - - """ - Get all the recipes from around the world - """ - recipes: [Recipe!]! -} - -""" -Object representing cooking recipe -""" -type Recipe { - averageRating: Float - creationDate: DateTime! - - """ - The recipe description with preparation info - """ - description: String - ratings: [Int!]! - ratingsCount(minRate: Int! = 0): Int! - specification: String @deprecated(reason: "Use `description` field instead") - title: String! -} - -input RecipeInput { - description: String - title: String! -} diff --git a/examples/esm/tsconfig.json b/examples/esm/tsconfig.json deleted file mode 100644 index 876c44cac..000000000 --- a/examples/esm/tsconfig.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "extends": "../../tsconfig.esm.json", - "include": ["../../src", "./"] -} diff --git a/examples/tsconfig.json b/examples/tsconfig.json index 2cb517951..b5d745b81 100644 --- a/examples/tsconfig.json +++ b/examples/tsconfig.json @@ -1,5 +1,4 @@ { "extends": "../tsconfig.cjs.json", - "include": ["../src", "./"], - "exclude": ["./esm"] + "include": ["../src", "./"] }