From 0f4e93fee88bfcd61b13392cf1ba6159b11c7757 Mon Sep 17 00:00:00 2001 From: s-hirano-ist <88515957+s-hirano-ist@users.noreply.github.com> Date: Fri, 27 Oct 2023 18:30:17 +0900 Subject: [PATCH] chore: add more settings (#1) * update README * add chore settings * fmt fix --- .eslintrc.cjs | 55 +++++++ .github/renovate.json5 | 34 +++++ .github/workflows/build.yaml | 39 +++++ .markdownlint-cli2.jsonc | 17 +-- .prettierignore | 2 + README.md | 68 ++++----- package.json | 2 +- prisma/seed.ts | 54 +++---- schema.graphql | 10 +- src/context.ts | 10 +- src/schema.ts | 281 +++++++++++++++++++---------------- src/server.ts | 21 ++- tsconfig.json | 4 +- 13 files changed, 366 insertions(+), 231 deletions(-) create mode 100644 .eslintrc.cjs create mode 100644 .github/renovate.json5 create mode 100644 .github/workflows/build.yaml create mode 100644 .prettierignore diff --git a/.eslintrc.cjs b/.eslintrc.cjs new file mode 100644 index 0000000..bcb2e23 --- /dev/null +++ b/.eslintrc.cjs @@ -0,0 +1,55 @@ +module.exports = { + env: { + browser: true, + es2021: true, + }, + extends: [ + "eslint:recommended", + "plugin:@typescript-eslint/recommended-type-checked", + "plugin:@typescript-eslint/stylistic-type-checked", + "plugin:import/recommended", + "plugin:import/typescript", + "prettier", + ], + parserOptions: { + ecmaVersion: "latest", + project: ["./tsconfig.json"], + }, + rules: { + "@typescript-eslint/ban-ts-comment": "off", + "react/prop-types": "off", + "@typescript-eslint/consistent-type-definitions": ["error", "type"], + "@typescript-eslint/no-unused-vars": [ + "warn", + { + argsIgnorePattern: "^_", + varsIgnorePattern: "^_", + caughtErrorsIgnorePattern: "^_", + }, + ], + "import/order": [ + "error", + { + groups: ["builtin", "external", "parent", "sibling", "index"], + pathGroupsExcludedImportTypes: [], + alphabetize: { order: "asc" }, + "newlines-between": "never", + }, + ], + // FIXME: delete + "@typescript-eslint/no-unsafe-member-access": "off", + "@typescript-eslint/no-misused-promises": "off", + "@typescript-eslint/no-unsafe-assignment": "off", + "@typescript-eslint/no-explicit-any": "off", + }, + root: true, + settings: { + "import/resolver": { + node: { + extensions: [".json", ".ts"], + moduleDirectory: ["node_modules", "src/"], + }, + }, + }, + ignorePatterns: ["prisma/seed.ts"], +}; diff --git a/.github/renovate.json5 b/.github/renovate.json5 new file mode 100644 index 0000000..55f44b3 --- /dev/null +++ b/.github/renovate.json5 @@ -0,0 +1,34 @@ +{ + timezone: "Asia/Tokyo", + baseBranches: ["main"], + extends: ["config:base", ":semanticCommitTypeAll(chore)"], + enabledManagers: ["npm"], + dependencyDashboard: true, + schedule: ["before 11am every monday"], + automergeSchedule: ["before 11am every tuesday"], + labels: ["dependencies"], + rangeStrategy: "bump", + lockFileMaintenance: { + enabled: true, + automerge: true, + }, + packageRules: [ + { + matchManagers: ["npm"], + matchDepTypes: ["devDependencies"], + matchPackagePatterns: ["lint", "prettier"], + automerge: true, + }, + { + matchManagers: ["npm"], + matchUpdateTypes: ["minor", "patch"], + matchCurrentVersion: "!/^0/", + automerge: true, + }, + { + extends: ["monorepo:ionic-native"], + matchUpdateTypes: ["patch", "minor"], + automerge: true, + }, + ], +} diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml new file mode 100644 index 0000000..52d4b07 --- /dev/null +++ b/.github/workflows/build.yaml @@ -0,0 +1,39 @@ +name: build +on: + push: +jobs: + build: + runs-on: ubuntu-latest + timeout-minutes: 20 + concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + steps: + - uses: actions/checkout@v4 + + - name: Install Node.js + uses: actions/setup-node@v3 + with: + node-version: "18" + + - name: Install pnpm + uses: pnpm/action-setup@v2 + with: + version: 8 + run_install: false + + - name: Get pnpm directory + shell: bash + run: | + echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV + + - name: Cache dependencies + uses: actions/cache@v3 + with: + path: ${{ env.STORE_PATH }} + key: ${{ runner.os }}-node-${{ hashFiles('**/pnpm-lock.yaml') }} + restore-keys: | + ${{ runner.os }}-node- + - run: pnpm i --frozen-lockfile + - run: pnpm fmt + - run: pnpm lint + - run: pnpm build diff --git a/.markdownlint-cli2.jsonc b/.markdownlint-cli2.jsonc index 2b55bfa..2e6a936 100644 --- a/.markdownlint-cli2.jsonc +++ b/.markdownlint-cli2.jsonc @@ -1,10 +1,9 @@ { - "config": { - "line-length": false, // MD013 行の長さ - "no-bare-urls": false, // MD034 URLのリンク化条件 - "no-duplicate-header": false, - "no-inline-html": false - }, - "ignores": [".git", "node_modules"] // 無視するディレクトリ - } - \ No newline at end of file + "config": { + "line-length": false, // MD013 行の長さ + "no-bare-urls": false, // MD034 URLのリンク化条件 + "no-duplicate-header": false, + "no-inline-html": false + }, + "ignores": [".git", "node_modules"] // 無視するディレクトリ +} diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..569ecc8 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,2 @@ +build/* +pnpm-lock.yaml diff --git a/README.md b/README.md index bfb0586..f14fe96 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Sample Apollo Server Project +# RSS dumper GraphQL ## Tech Stack @@ -8,15 +8,14 @@ > https://github.com/prisma/prisma-examples/tree/latest/typescript/graphql-nexus - # GraphQL Server Example This example shows how to implement a **GraphQL server with TypeScript** with the following stack: -- [**Apollo Server**](https://github.com/apollographql/apollo-server): HTTP server for GraphQL APIs -- [**GraphQL Nexus**](https://nexusjs.org/docs/): GraphQL schema definition and resolver implementation -- [**Prisma Client**](https://www.prisma.io/docs/concepts/components/prisma-client): Databases access (ORM) -- [**Prisma Migrate**](https://www.prisma.io/docs/concepts/components/prisma-migrate): Database migrations +- [**Apollo Server**](https://github.com/apollographql/apollo-server): HTTP server for GraphQL APIs +- [**GraphQL Nexus**](https://nexusjs.org/docs/): GraphQL schema definition and resolver implementation +- [**Prisma Client**](https://www.prisma.io/docs/concepts/components/prisma-client): Databases access (ORM) +- [**Prisma Migrate**](https://www.prisma.io/docs/concepts/components/prisma-migrate): Database migrations - [**SQLite**](https://www.sqlite.org/index.html): Local, file-based SQL database ## Contents @@ -71,7 +70,6 @@ npx prisma migrate dev --name init When `npx prisma migrate dev` is executed against a newly created database, seeding is also triggered. The seed file in [`prisma/seed.ts`](./prisma/seed.ts) will be executed and your database will be populated with the sample data. - ### 3. Start the GraphQL server Launch your GraphQL server with this command: @@ -82,7 +80,6 @@ npm run dev Navigate to [http://localhost:4000](http://localhost:4000) in your browser to explore the API of your GraphQL server in a [GraphQL Playground](https://github.com/prisma/graphql-playground). - ## Using the GraphQL API The schema that specifies the API operations of your GraphQL server is defined in [`./schema.graphql`](./schema.graphql). Below are a number of operations that you can send to the API using the GraphQL Playground. @@ -113,11 +110,7 @@ query { ```graphql { - draftsByUser( - userUniqueInput: { - email: "mahmoud@prisma.io" - } - ) { + draftsByUser(userUniqueInput: { email: "mahmoud@prisma.io" }) { id title content @@ -131,7 +124,6 @@ query { } ``` - ### Create a new user ```graphql @@ -209,9 +201,7 @@ mutation { ```graphql { - feed( - searchString: "prisma" - ) { + feed(searchString: "prisma") { id title content @@ -224,11 +214,7 @@ mutation { ```graphql { - feed( - skip: 2 - take: 2 - orderBy: { updatedAt: desc } - ) { + feed(skip: 2, take: 2, orderBy: { updatedAt: desc }) { id updatedAt title @@ -242,7 +228,7 @@ mutation { ```graphql { - postById(id: __POST_ID__ ) { + postById(id: __POST_ID__) { id title content @@ -255,7 +241,7 @@ Note that you need to replace the `__POST_ID__` placeholder with an actual `id` ```graphql { - postById(id: 5 ) { + postById(id: 5) { id title content @@ -386,8 +372,8 @@ const User = objectType({ + type: 'Profile', + resolve: (parent, _, context) => { + return context.prisma.user -+ .findUnique({ -+ where: { id: parent.id }, ++ .findUnique({ ++ where: { id: parent.id }, + }) + .profile(); + }, @@ -438,7 +424,7 @@ const Mutation = objectType({ + }), + ), + bio: stringArg() -+ }, ++ }, + resolve: async (_, args, context) => { + return context.prisma.profile.create({ + data: { @@ -463,9 +449,7 @@ Finally, you can test the new mutation like this: ```graphql mutation { addProfileForUser( - userUniqueInput: { - email: "mahmoud@prisma.io" - } + userUniqueInput: { email: "mahmoud@prisma.io" } bio: "I like turtles" ) { id @@ -487,12 +471,12 @@ Here are some more sample Prisma Client queries on the new Profile ```ts const profile = await prisma.profile.create({ data: { - bio: 'Hello World', + bio: "Hello World", user: { - connect: { email: 'alice@prisma.io' }, + connect: { email: "alice@prisma.io" }, }, }, -}) +}); ``` ##### Create a new user with a new profile @@ -500,37 +484,37 @@ const profile = await prisma.profile.create({ ```ts const user = await prisma.user.create({ data: { - email: 'john@prisma.io', - name: 'John', + email: "john@prisma.io", + name: "John", profile: { create: { - bio: 'Hello World', + bio: "Hello World", }, }, }, -}) +}); ``` ##### Update the profile of an existing user ```ts const userWithUpdatedProfile = await prisma.user.update({ - where: { email: 'alice@prisma.io' }, + where: { email: "alice@prisma.io" }, data: { profile: { update: { - bio: 'Hello Friends', + bio: "Hello Friends", }, }, }, -}) +}); ``` ## Switch to another database (e.g. PostgreSQL, MySQL, SQL Server, MongoDB) -If you want to try this example with another database than SQLite, you can adjust the the database connection in [`prisma/schema.prisma`](./prisma/schema.prisma) by reconfiguring the `datasource` block. +If you want to try this example with another database than SQLite, you can adjust the the database connection in [`prisma/schema.prisma`](./prisma/schema.prisma) by reconfiguring the `datasource` block. Learn more about the different connection configurations in the [docs](https://www.prisma.io/docs/reference/database-reference/connection-urls). @@ -597,6 +581,7 @@ datasource db { url = "mongodb://USERNAME:PASSWORD@HOST/DATABASE?authSource=admin&retryWrites=true&w=majority" } ``` + Because MongoDB is currently in [Preview](https://www.prisma.io/docs/about/releases#preview), you need to specify the `previewFeatures` on your `generator` block: ``` @@ -605,6 +590,7 @@ generator client { previewFeatures = ["mongodb"] } ``` + ## Next steps diff --git a/package.json b/package.json index 0033168..64bcb6f 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "scripts": { "dev": "ts-node-dev --no-notify --respawn --transpile-only src/server", "start": "node dist/server", - "build": "npm -s run clean && npm -s run generate && tsc", + "build": "npm -s run clean && npm -s run generate && tsc", "check:types": "tsc --noEmit", "fmt": "prettier --check .", "fmt:fix": "prettier --write .", diff --git a/prisma/seed.ts b/prisma/seed.ts index 69d949a..72c7cf7 100644 --- a/prisma/seed.ts +++ b/prisma/seed.ts @@ -1,29 +1,29 @@ -import { PrismaClient, Prisma } from '@prisma/client' +import { PrismaClient, Prisma } from "@prisma/client"; -const prisma = new PrismaClient() +const prisma = new PrismaClient(); const userData: Prisma.UserCreateInput[] = [ { - name: 'Alice', - email: 'alice@prisma.io', + name: "Alice", + email: "alice@prisma.io", posts: { create: [ { - title: 'Join the Prisma Slack', - content: 'https://slack.prisma.io', + title: "Join the Prisma Slack", + content: "https://slack.prisma.io", published: true, }, ], }, }, { - name: 'Nilu', - email: 'nilu@prisma.io', + name: "Nilu", + email: "nilu@prisma.io", posts: { create: [ { - title: 'Follow Prisma on Twitter', - content: 'https://www.twitter.com/prisma', + title: "Follow Prisma on Twitter", + content: "https://www.twitter.com/prisma", published: true, viewCount: 42, }, @@ -31,42 +31,42 @@ const userData: Prisma.UserCreateInput[] = [ }, }, { - name: 'Mahmoud', - email: 'mahmoud@prisma.io', + name: "Mahmoud", + email: "mahmoud@prisma.io", posts: { create: [ { - title: 'Ask a question about Prisma on GitHub', - content: 'https://www.github.com/prisma/prisma/discussions', + title: "Ask a question about Prisma on GitHub", + content: "https://www.github.com/prisma/prisma/discussions", published: true, viewCount: 128, }, { - title: 'Prisma on YouTube', - content: 'https://pris.ly/youtube', + title: "Prisma on YouTube", + content: "https://pris.ly/youtube", }, ], }, }, -] +]; async function main() { - console.log(`Start seeding ...`) + console.log(`Start seeding ...`); for (const u of userData) { const user = await prisma.user.create({ data: u, - }) - console.log(`Created user with id: ${user.id}`) + }); + console.log(`Created user with id: ${user.id}`); } - console.log(`Seeding finished.`) + console.log(`Seeding finished.`); } main() .then(async () => { - await prisma.$disconnect() - }) - .catch(async (e) => { - console.error(e) - await prisma.$disconnect() - process.exit(1) + await prisma.$disconnect(); }) + .catch(async e => { + console.error(e); + await prisma.$disconnect(); + process.exit(1); + }); diff --git a/schema.graphql b/schema.graphql index cd4ce1a..fee1f7a 100644 --- a/schema.graphql +++ b/schema.graphql @@ -1,7 +1,6 @@ ### This file was generated by Nexus Schema ### Do not make changes to this file directly - """ A date-time string at UTC, such as 2007-12-03T10:15:30Z, compliant with the `date-time` format outlined in section 5.6 of the RFC 3339 profile of the ISO 8601 standard for representation of dates and times using the Gregorian calendar. """ @@ -45,7 +44,12 @@ type Profile { type Query { allUsers: [User!]! draftsByUser(userUniqueInput: UserUniqueInput!): [Post] - feed(orderBy: PostOrderByUpdatedAtInput, searchString: String, skip: Int, take: Int): [Post!]! + feed( + orderBy: PostOrderByUpdatedAtInput + searchString: String + skip: Int + take: Int + ): [Post!]! postById(id: Int): Post } @@ -71,4 +75,4 @@ input UserCreateInput { input UserUniqueInput { email: String id: Int -} \ No newline at end of file +} diff --git a/src/context.ts b/src/context.ts index 029c79c..f1a7f02 100755 --- a/src/context.ts +++ b/src/context.ts @@ -1,11 +1,11 @@ -import { PrismaClient } from '@prisma/client' +import { PrismaClient } from "@prisma/client"; export type Context = { - prisma: PrismaClient -} + prisma: PrismaClient; +}; -const prisma = new PrismaClient() +const prisma = new PrismaClient(); export const createContext = async () => ({ prisma, -}) +}); diff --git a/src/schema.ts b/src/schema.ts index a4579a7..60f0506 100644 --- a/src/schema.ts +++ b/src/schema.ts @@ -8,42 +8,42 @@ import { arg, asNexusMethod, enumType, -} from 'nexus' -import { DateTimeResolver } from 'graphql-scalars' -import { Context } from './context' +} from "nexus"; +import { DateTimeResolver } from "graphql-scalars"; +import { Context } from "./context"; -export const DateTime = asNexusMethod(DateTimeResolver, 'date') +export const DateTime = asNexusMethod(DateTimeResolver, "date"); const Query = objectType({ - name: 'Query', + name: "Query", definition(t) { - t.nonNull.list.nonNull.field('allUsers', { - type: 'User', + t.nonNull.list.nonNull.field("allUsers", { + type: "User", resolve: (_parent, _args, context: Context) => { - return context.prisma.user.findMany() + return context.prisma.user.findMany(); }, - }) + }); - t.nullable.field('postById', { - type: 'Post', + t.nullable.field("postById", { + type: "Post", args: { id: intArg(), }, resolve: (_parent, args, context: Context) => { return context.prisma.post.findUnique({ where: { id: args.id || undefined }, - }) + }); }, - }) + }); - t.nonNull.list.nonNull.field('feed', { - type: 'Post', + t.nonNull.list.nonNull.field("feed", { + type: "Post", args: { searchString: stringArg(), skip: intArg(), take: intArg(), orderBy: arg({ - type: 'PostOrderByUpdatedAtInput', + type: "PostOrderByUpdatedAtInput", }), }, resolve: (_parent, args, context: Context) => { @@ -54,7 +54,7 @@ const Query = objectType({ { content: { contains: args.searchString } }, ], } - : {} + : {}; return context.prisma.post.findMany({ where: { @@ -64,16 +64,16 @@ const Query = objectType({ take: args.take || undefined, skip: args.skip || undefined, orderBy: args.orderBy || undefined, - }) + }); }, - }) + }); - t.list.field('draftsByUser', { - type: 'Post', + t.list.field("draftsByUser", { + type: "Post", args: { userUniqueInput: nonNull( arg({ - type: 'UserUniqueInput', + type: "UserUniqueInput", }), ), }, @@ -89,28 +89,28 @@ const Query = objectType({ where: { published: false, }, - }) + }); }, - }) + }); }, -}) +}); const Mutation = objectType({ - name: 'Mutation', + name: "Mutation", definition(t) { - t.nonNull.field('signupUser', { - type: 'User', + t.nonNull.field("signupUser", { + type: "User", args: { data: nonNull( arg({ - type: 'UserCreateInput', + type: "UserCreateInput", }), ), }, resolve: (_, args, context: Context) => { - const postData = args.data.posts?.map((post) => { - return { title: post.title, content: post.content || undefined } - }) + const postData = args.data.posts?.map(post => { + return { title: post.title, content: post.content || undefined }; + }); return context.prisma.user.create({ data: { name: args.data.name, @@ -119,16 +119,16 @@ const Mutation = objectType({ create: postData, }, }, - }) + }); }, - }) + }); - t.field('createDraft', { - type: 'Post', + t.field("createDraft", { + type: "Post", args: { data: nonNull( arg({ - type: 'PostCreateInput', + type: "PostCreateInput", }), ), authorEmail: nonNull(stringArg()), @@ -142,12 +142,12 @@ const Mutation = objectType({ connect: { email: args.authorEmail }, }, }, - }) + }); }, - }) + }); - t.field('togglePublishPost', { - type: 'Post', + t.field("togglePublishPost", { + type: "Post", args: { id: nonNull(intArg()), }, @@ -158,21 +158,21 @@ const Mutation = objectType({ select: { published: true, }, - }) + }); return context.prisma.post.update({ where: { id: args.id || undefined }, data: { published: !post?.published }, - }) + }); } catch (e) { throw new Error( `Post with ID ${args.id} does not exist in the database.`, - ) + ); } }, - }) + }); - t.field('incrementPostViewCount', { - type: 'Post', + t.field("incrementPostViewCount", { + type: "Post", args: { id: nonNull(intArg()), }, @@ -184,31 +184,31 @@ const Mutation = objectType({ increment: 1, }, }, - }) + }); }, - }) + }); - t.field('deletePost', { - type: 'Post', + t.field("deletePost", { + type: "Post", args: { id: nonNull(intArg()), }, resolve: (_, args, context: Context) => { return context.prisma.post.delete({ where: { id: args.id }, - }) + }); }, }), - t.field('addProfileForUser', { - type: 'Profile', + t.field("addProfileForUser", { + type: "Profile", args: { userUniqueInput: nonNull( arg({ - type: 'UserUniqueInput', + type: "UserUniqueInput", }), ), - bio: stringArg() - }, + bio: stringArg(), + }, resolve: async (_, args, context) => { return context.prisma.profile.create({ data: { @@ -217,126 +217,143 @@ const Mutation = objectType({ connect: { id: args.userUniqueInput.id || undefined, email: args.userUniqueInput.email || undefined, - } - } - } - }) - } - }) + }, + }, + }, + }); + }, + }); }, -}) +}); const Profile = objectType({ - name: 'Profile', + name: "Profile", definition(t) { - t.nonNull.int('id') - t.string('bio') - t.field('user', { - type: 'User', + t.nonNull.int("id"); + t.string("bio"); + t.field("user", { + type: "User", resolve: (parent, _, context) => { return context.prisma.profile .findUnique({ where: { id: parent.id || undefined }, }) - .user() + .user(); }, - }) + }); }, -}) +}); const User = objectType({ - name: 'User', + name: "User", definition(t) { - t.nonNull.int('id') - t.string('name') - t.nonNull.string('email') - t.nonNull.list.nonNull.field('posts', { - type: 'Post', + t.nonNull.int("id"); + t.string("name"); + t.nonNull.string("email"); + t.nonNull.list.nonNull.field("posts", { + type: "Post", resolve: (parent, _, context) => { - return [{ - id:0,createdAt:new Date(),updatedAt:new Date(),title:"title",content:"content",published:true,viewCount:0,authorId:0}, + return [ { - id:0,createdAt:new Date(),updatedAt:new Date(),title:"title",content:"content",published:true,viewCount:0,author:{id:0,name:"name",email:"email"}, - }] + id: 0, + createdAt: new Date(), + updatedAt: new Date(), + title: "title", + content: "content", + published: true, + viewCount: 0, + authorId: 0, + }, + { + id: 0, + createdAt: new Date(), + updatedAt: new Date(), + title: "title", + content: "content", + published: true, + viewCount: 0, + author: { id: 0, name: "name", email: "email" }, + }, + ]; // return context.prisma.user // .findUnique({ // where: { id: parent.id || undefined }, // }) // .posts() - } - }), - t.field('profile', { - type: 'Profile', - resolve: (parent, _, context) => { - return context.prisma.user - .findUnique({ - where: { id: parent.id }, - }) - .profile(); }, - }) + }), + t.field("profile", { + type: "Profile", + resolve: (parent, _, context) => { + return context.prisma.user + .findUnique({ + where: { id: parent.id }, + }) + .profile(); + }, + }); }, }); const Post = objectType({ - name: 'Post', + name: "Post", definition(t) { - t.nonNull.int('id') - t.nonNull.field('createdAt', { type: 'DateTime' }) - t.nonNull.field('updatedAt', { type: 'DateTime' }) - t.nonNull.string('title') - t.string('content') - t.nonNull.boolean('published') - t.nonNull.int('viewCount') - t.field('author', { - type: 'User', + t.nonNull.int("id"); + t.nonNull.field("createdAt", { type: "DateTime" }); + t.nonNull.field("updatedAt", { type: "DateTime" }); + t.nonNull.string("title"); + t.string("content"); + t.nonNull.boolean("published"); + t.nonNull.int("viewCount"); + t.field("author", { + type: "User", resolve: (parent, _, context: Context) => { return context.prisma.post .findUnique({ where: { id: parent.id || undefined }, }) - .author() + .author(); }, - }) + }); }, -}) +}); const SortOrder = enumType({ - name: 'SortOrder', - members: ['asc', 'desc'], -}) + name: "SortOrder", + members: ["asc", "desc"], +}); const PostOrderByUpdatedAtInput = inputObjectType({ - name: 'PostOrderByUpdatedAtInput', + name: "PostOrderByUpdatedAtInput", definition(t) { - t.nonNull.field('updatedAt', { type: 'SortOrder' }) + t.nonNull.field("updatedAt", { type: "SortOrder" }); }, -}) +}); const UserUniqueInput = inputObjectType({ - name: 'UserUniqueInput', + name: "UserUniqueInput", definition(t) { - t.int('id') - t.string('email') + t.int("id"); + t.string("email"); }, -}) +}); const PostCreateInput = inputObjectType({ - name: 'PostCreateInput', + name: "PostCreateInput", definition(t) { - t.nonNull.string('title') - t.string('content') + t.nonNull.string("title"); + t.string("content"); }, -}) +}); const UserCreateInput = inputObjectType({ - name: 'UserCreateInput', + name: "UserCreateInput", definition(t) { - t.nonNull.string('email') - t.string('name') - t.list.nonNull.field('posts', { type: 'PostCreateInput' }) + t.nonNull.string("email"); + t.string("name"); + t.list.nonNull.field("posts", { type: "PostCreateInput" }); }, -}) +}); export const schema = makeSchema({ types: [ @@ -353,19 +370,19 @@ export const schema = makeSchema({ DateTime, ], outputs: { - schema: __dirname + '/../schema.graphql', - typegen: __dirname + '/generated/nexus.ts', + schema: __dirname + "/../schema.graphql", + typegen: __dirname + "/generated/nexus.ts", }, contextType: { - module: require.resolve('./context'), - export: 'Context', + module: require.resolve("./context"), + export: "Context", }, sourceTypes: { modules: [ { - module: '@prisma/client', - alias: 'prisma', + module: "@prisma/client", + alias: "prisma", }, ], }, -}) +}); diff --git a/src/server.ts b/src/server.ts index 3e8276a..31efcbf 100755 --- a/src/server.ts +++ b/src/server.ts @@ -1,21 +1,20 @@ -import { ApolloServer } from '@apollo/server' -import { startStandaloneServer } from '@apollo/server/standalone' -import { schema } from './schema' -import { Context, createContext } from './context' +import { ApolloServer } from "@apollo/server"; +import { startStandaloneServer } from "@apollo/server/standalone"; +import { schema } from "./schema"; +import { Context, createContext } from "./context"; const start = async () => { - const server = new ApolloServer({ schema,csrfPrevention:true }) + const server = new ApolloServer({ schema, csrfPrevention: true }); const { url } = await startStandaloneServer(server, { context: createContext, - listen: { port: 4000 } - }) + listen: { port: 4000 }, + }); console.log(`\ 🚀 Server ready at: ${url} ⭐️ See sample queries: http://pris.ly/e/ts/graphql-nexus#using-the-graphql-api - `) + `); +}; -} - -start() +start(); diff --git a/tsconfig.json b/tsconfig.json index 2145d8c..1e6779a 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -4,7 +4,7 @@ "rootDir": "src", "esModuleInterop": true, "lib": ["esnext"], - "strict": true, + "strict": true }, "include": ["src/**/*"] -} \ No newline at end of file +}