Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/apollo-server/Query.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import IPerson from "./interfaces/IPerson";
import User from "./models/User";
import IPerson from "./interfaces/IPerson.js";
import User from "./models/User.js";

/** @gqlQueryField */
export function person(): IPerson {
Expand Down
2 changes: 1 addition & 1 deletion examples/apollo-server/models/Group.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import User from "./User";
import User from "./User.js";

/** @gqlType */
export default class Group {
Expand Down
4 changes: 2 additions & 2 deletions examples/apollo-server/models/User.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import IPerson from "../interfaces/IPerson";
import Group from "./Group";
import IPerson from "../interfaces/IPerson.js";
import Group from "./Group.js";

/** @gqlType User */
export default class UserResolver implements IPerson {
Expand Down
1 change: 1 addition & 0 deletions examples/apollo-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "grats-example-apollo-server",
"version": "0.0.0",
"description": "Example server showcasing Grats used with Apollo Server",
"type": "module",
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we're migrating every example project to es modules. Are we really forcing all of our users to upgrade? Ideally this PR is as minimally invasive as possible and the examples could demonstrate that most consumers will NOT need to make changes to upgrade to this version.

If we really are forcing all users to upgrade or do some other workaround, maybe we need an example cjs project that shows how to achieve that wrokaround?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately this is unavoidable. With grats now being an ESM package ("type": "module"), TypeScript in CJS mode with module: "NodeNext" raises TS1479 even for import type from an ESM package. So any user on module: "NodeNext" (the recommended Node.js setting) needs "type": "module" in their package.json. Users with bundler-based setups (webpack/vite with moduleResolution: "bundler") don't need to change anything since bundler resolution doesn't enforce the CJS/ESM boundary.

"main": "index.js",
"scripts": {
"start": "tsc && node dist/server.js",
Expand Down
8 changes: 4 additions & 4 deletions examples/apollo-server/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
* Do not manually edit. Regenerate by running `npx grats`.
*/

import UserClass from "./models/User";
import queryAllUsersResolver from "./models/User";
import queryMeResolver from "./models/User";
import UserClass from "./models/User.js";
import queryAllUsersResolver from "./models/User.js";
import queryMeResolver from "./models/User.js";
import { GraphQLSchema, GraphQLObjectType, GraphQLNonNull, GraphQLList, GraphQLString, GraphQLInterfaceType } from "graphql";
import { person as queryPersonResolver } from "./Query";
import { person as queryPersonResolver } from "./Query.js";
export function getSchema(): GraphQLSchema {
const GroupType: GraphQLObjectType = new GraphQLObjectType({
name: "Group",
Expand Down
2 changes: 1 addition & 1 deletion examples/apollo-server/server.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ApolloServer } from "@apollo/server";
import { startStandaloneServer } from "@apollo/server/standalone";
import { getSchema } from "./schema";
import { getSchema } from "./schema.js";

async function main() {
const server = new ApolloServer({ schema: getSchema() });
Expand Down
3 changes: 2 additions & 1 deletion examples/apollo-server/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"grats": {
"nullableByDefault": false
"nullableByDefault": false,
"importModuleSpecifierEnding": ".js"
},
"compilerOptions": {
"outDir": "dist",
Expand Down
2 changes: 1 addition & 1 deletion examples/express-graphql-http/interfaces/IPerson.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import User from "../models/User";
import User from "../models/User.js";

/** @gqlInterface */
export default interface IPerson {
Expand Down
2 changes: 1 addition & 1 deletion examples/express-graphql-http/models/Group.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import User from "./User";
import User from "./User.js";

/** @gqlType */
export default class Group {
Expand Down
4 changes: 2 additions & 2 deletions examples/express-graphql-http/models/User.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import IPerson from "../interfaces/IPerson";
import Group from "./Group";
import IPerson from "../interfaces/IPerson.js";
import Group from "./Group.js";

/** @gqlType */
export default class User implements IPerson {
Expand Down
1 change: 1 addition & 0 deletions examples/express-graphql-http/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "grats-example-express-graphql-http",
"version": "0.0.0",
"description": "Example server showcasing Grats used with Express and graphql-http ",
"type": "module",
"main": "index.js",
"scripts": {
"start": "tsc && node dist/server.js",
Expand Down
8 changes: 4 additions & 4 deletions examples/express-graphql-http/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
* Do not manually edit. Regenerate by running `npx grats`.
*/

import UserClass from "./models/User";
import queryAllUsersResolver from "./models/User";
import queryMeResolver from "./models/User";
import UserClass from "./models/User.js";
import queryAllUsersResolver from "./models/User.js";
import queryMeResolver from "./models/User.js";
import { GraphQLSchema, GraphQLObjectType, GraphQLNonNull, GraphQLList, GraphQLString, GraphQLInterfaceType } from "graphql";
import { person as queryPersonResolver } from "./interfaces/IPerson";
import { person as queryPersonResolver } from "./interfaces/IPerson.js";
export function getSchema(): GraphQLSchema {
const GroupType: GraphQLObjectType = new GraphQLObjectType({
name: "Group",
Expand Down
4 changes: 2 additions & 2 deletions examples/express-graphql-http/server.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as express from "express";
import express from "express";
import { createHandler } from "graphql-http/lib/use/express";
import { getSchema } from "./schema";
import { getSchema } from "./schema.js";

const app = express();

Expand Down
16 changes: 7 additions & 9 deletions examples/express-graphql-http/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
{
// Most ts-node options can be specified here using their programmatic names.
"ts-node": {
"files": true,
// It is faster to skip typechecking.
// Remove if you want ts-node to do typechecking.
"transpileOnly": false
},
"grats": {
"nullableByDefault": false
"nullableByDefault": false,
"importModuleSpecifierEnding": ".js"
},
"compilerOptions": {
"outDir": "dist",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"target": "esnext",
"lib": ["esnext"],
"strict": true
"strict": true,
"skipLibCheck": true
}
}
1 change: 1 addition & 0 deletions examples/incremental-migration/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "grats-example-migration",
"version": "0.0.0",
"description": "Example server showcasing an incremental migration from Pothos to Grats",
"type": "module",
"main": "index.js",
"scripts": {
"start": "tsc && node dist/server.js",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// DO NOT USE DIRECTLY. Prefer the merged schema in `./mergedSchema.ts`.

import { GraphQLSchema, GraphQLObjectType, GraphQLNonNull, GraphQLString, GraphQLID } from "graphql";
import { user as queryUserResolver } from "./../models";
import { user as queryUserResolver } from "./../models.js";
export function getSchema(): GraphQLSchema {
const UserType: GraphQLObjectType = new GraphQLObjectType({
name: "User",
Expand Down
8 changes: 6 additions & 2 deletions examples/incremental-migration/schemas/mergedSchema.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { schema as legacySchema } from "./pothosSchema";
import { getSchema as getGratsSchema } from "./gratsGeneratedSchema";
import { schema as legacySchema } from "./pothosSchema.js";
import { getSchema as getGratsSchema } from "./gratsGeneratedSchema.js";
import { mergeSchemas } from "@graphql-tools/schema";
import { printSchema, lexicographicSortSchema } from "graphql";
import fs from "fs";
import path from "path";
import { fileURLToPath } from "url";

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

/**
* Merges the Pothos (legacy) and Grats (new) schemas into a single schema for
Expand Down
2 changes: 1 addition & 1 deletion examples/incremental-migration/schemas/pothosSchema.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Users, Posts, Comments, User, Post, Comment } from "../models";
import { Users, Posts, Comments, User, Post, Comment } from "../models.js";
import SchemaBuilder from "@pothos/core";
const builder = new SchemaBuilder({});

Expand Down
2 changes: 1 addition & 1 deletion examples/incremental-migration/server.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createServer } from "node:http";
import { createYoga } from "graphql-yoga";
import { schema } from "./schemas/mergedSchema";
import { schema } from "./schemas/mergedSchema.js";

const yoga = createYoga({ schema });

Expand Down
3 changes: 2 additions & 1 deletion examples/incremental-migration/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"tsSchema": "./schemas/gratsGeneratedSchema.ts",
"graphqlSchema": "gratsSchema.graphql",
"tsSchemaHeader": "// DO NOT USE DIRECTLY. Prefer the merged schema in `./mergedSchema.ts`.",
"schemaHeader": "# DO NOT USE DIRECTLY. Prefer the merged schema in `../schema.graphql`."
"schemaHeader": "# DO NOT USE DIRECTLY. Prefer the merged schema in `../schema.graphql`.",
"importModuleSpecifierEnding": ".js"
},
"compilerOptions": {
"outDir": "dist",
Expand Down
3 changes: 2 additions & 1 deletion examples/next-js/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"grats": {
"nullableByDefault": false
"nullableByDefault": false,
"importModuleSpecifierEnding": ""
},
"compilerOptions": {
"target": "es5",
Expand Down
10 changes: 5 additions & 5 deletions examples/production-app/Database.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { PubSub } from "./PubSub";
import { VC } from "./ViewerContext";
import { Like } from "./models/Like";
import { Post } from "./models/Post";
import { User } from "./models/User";
import { PubSub } from "./PubSub.js";
import { VC } from "./ViewerContext.js";
import { Like } from "./models/Like.js";
import { Post } from "./models/Post.js";
import { User } from "./models/User.js";

/**
* This module is intended to represent a database.
Expand Down
8 changes: 4 additions & 4 deletions examples/production-app/ViewerContext.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import DataLoader from "dataloader";
import { getPostsByIds, getUsersByIds, getLikesByIds } from "./Database";
import { getPostsByIds, getUsersByIds, getLikesByIds } from "./Database.js";
import { YogaInitialContext } from "graphql-yoga";
import { Post } from "./models/Post";
import { User } from "./models/User";
import { Like } from "./models/Like";
import { Post } from "./models/Post.js";
import { User } from "./models/User.js";
import { Like } from "./models/Like.js";

/**
* Viewer Context
Expand Down
2 changes: 1 addition & 1 deletion examples/production-app/graphql/CustomScalars.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Kind } from "graphql";
import type { SchemaConfig } from "../schema";
import type { SchemaConfig } from "../schema.js";

// TODO: Consider switching serialization to follow https://ibm.github.io/graphql-specs/custom-scalars/date.html

Expand Down
2 changes: 1 addition & 1 deletion examples/production-app/graphql/Node.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { fromGlobalId, toGlobalId } from "graphql-relay";
import { ID } from "grats";
import { VC } from "../ViewerContext";
import { VC } from "../ViewerContext.js";

/**
* Converts a globally unique ID into a local ID asserting
Expand Down
2 changes: 1 addition & 1 deletion examples/production-app/graphql/directives.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { defaultFieldResolver, GraphQLError, GraphQLSchema } from "graphql";
import { Int } from "grats";
import { Ctx } from "../ViewerContext";
import { Ctx } from "../ViewerContext.js";
import { getDirective, MapperKind, mapSchema } from "@graphql-tools/utils";

/**
Expand Down
16 changes: 8 additions & 8 deletions examples/production-app/models/Like.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import * as DB from "../Database";
import { VC } from "../ViewerContext";
import { GraphQLNode, getLocalTypeAssert } from "../graphql/Node";
import { User } from "./User";
import { Model } from "./Model";
import { ID } from "../../../dist/src";
import { GqlDate } from "../graphql/CustomScalars";
import { Post } from "./Post";
import * as DB from "../Database.js";
import { VC } from "../ViewerContext.js";
import { GraphQLNode, getLocalTypeAssert } from "../graphql/Node.js";
import { User } from "./User.js";
import { Model } from "./Model.js";
import { ID } from "../../../dist/src/index.js";
import { GqlDate } from "../graphql/CustomScalars.js";
import { Post } from "./Post.js";

/**
* A reaction from a user indicating that they like a post.
Expand Down
12 changes: 6 additions & 6 deletions examples/production-app/models/LikeConnection.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { GqlInfo, Int } from "grats";
import * as DB from "../Database";
import { VC } from "../ViewerContext";
import { Like } from "./Like";
import { PageInfo } from "../graphql/Connection";
import { PubSub } from "../PubSub";
import * as DB from "../Database.js";
import { VC } from "../ViewerContext.js";
import { Like } from "./Like.js";
import { PageInfo } from "../graphql/Connection.js";
import { PubSub } from "../PubSub.js";
import { filter, map, pipe } from "graphql-yoga";
import { getLocalTypeAssert } from "../graphql/Node";
import { getLocalTypeAssert } from "../graphql/Node.js";
import { connectionFromSelectOrCount } from "../graphql/gqlUtils.js";

/** @gqlType */
Expand Down
2 changes: 1 addition & 1 deletion examples/production-app/models/Model.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { VC } from "../ViewerContext";
import { VC } from "../ViewerContext.js";

/**
* Generic model class built around a database row
Expand Down
16 changes: 8 additions & 8 deletions examples/production-app/models/Post.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import * as DB from "../Database";
import { VC } from "../ViewerContext";
import { GraphQLNode, getLocalTypeAssert } from "../graphql/Node";
import { User } from "./User";
import { Model } from "./Model";
import { GqlInfo, ID, Int } from "../../../dist/src";
import { GqlDate } from "../graphql/CustomScalars";
import { LikeConnection } from "./LikeConnection";
import * as DB from "../Database.js";
import { VC } from "../ViewerContext.js";
import { GraphQLNode, getLocalTypeAssert } from "../graphql/Node.js";
import { User } from "./User.js";
import { Model } from "./Model.js";
import { GqlInfo, ID, Int } from "../../../dist/src/index.js";
import { GqlDate } from "../graphql/CustomScalars.js";
import { LikeConnection } from "./LikeConnection.js";
import { connectionFromSelectOrCount } from "../graphql/gqlUtils.js";

/**
Expand Down
8 changes: 4 additions & 4 deletions examples/production-app/models/PostConnection.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { GqlInfo, Int } from "grats";
import * as DB from "../Database";
import { VC } from "../ViewerContext";
import { Post } from "./Post";
import { Connection } from "../graphql/Connection";
import * as DB from "../Database.js";
import { VC } from "../ViewerContext.js";
import { Post } from "./Post.js";
import { Connection } from "../graphql/Connection.js";
import { connectionFromSelectOrCount } from "../graphql/gqlUtils.js";

/**
Expand Down
12 changes: 6 additions & 6 deletions examples/production-app/models/User.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import * as DB from "../Database";
import { VC } from "../ViewerContext";
import { GraphQLNode } from "../graphql/Node";
import { Model } from "./Model";
import { Post } from "./Post";
import { Connection } from "../graphql/Connection";
import * as DB from "../Database.js";
import { VC } from "../ViewerContext.js";
import { GraphQLNode } from "../graphql/Node.js";
import { Model } from "./Model.js";
import { Post } from "./Post.js";
import { Connection } from "../graphql/Connection.js";
import { GqlInfo, Int } from "../../../dist/src/Types.js";
import { connectionFromSelectOrCount } from "../graphql/gqlUtils.js";

Expand Down
8 changes: 4 additions & 4 deletions examples/production-app/models/UserConnection.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { GqlInfo, Int } from "grats";
import * as DB from "../Database";
import { VC } from "../ViewerContext";
import { User } from "./User";
import { Connection } from "../graphql/Connection";
import * as DB from "../Database.js";
import { VC } from "../ViewerContext.js";
import { User } from "./User.js";
import { Connection } from "../graphql/Connection.js";
import { connectionFromSelectOrCount } from "../graphql/gqlUtils.js";

/**
Expand Down
8 changes: 4 additions & 4 deletions examples/production-app/models/Viewer.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as DB from "../Database";
import { VC } from "../ViewerContext";
import { Post } from "./Post";
import { User } from "./User";
import * as DB from "../Database.js";
import { VC } from "../ViewerContext.js";
import { Post } from "./Post.js";
import { User } from "./User.js";

/**
* The currently authenticated viewer.
Expand Down
1 change: 1 addition & 0 deletions examples/production-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "grats-production-app-example",
"version": "0.0.0",
"description": "Example server showcasing Grats in a feature complete server",
"type": "module",
"main": "index.js",
"scripts": {
"start": "tsc && node dist/server.js",
Expand Down
Loading
Loading