sample: update graphql samples

This commit is contained in:
Kamil Myśliwiec
2025-01-17 11:10:58 +01:00
parent 1b5f16863b
commit 96cdb827c8
19 changed files with 81 additions and 80 deletions

View File

@@ -21,10 +21,10 @@
"dependencies": {
"@apollo/server": "4.11.3",
"@graphql-tools/utils": "10.7.2",
"@nestjs/apollo": "12.2.2",
"@nestjs/apollo": "13.0.0",
"@nestjs/common": "11.0.1",
"@nestjs/core": "11.0.1",
"@nestjs/graphql": "12.2.2",
"@nestjs/graphql": "13.0.0",
"@nestjs/platform-express": "11.0.1",
"class-transformer": "0.5.1",
"class-validator": "0.14.1",

View File

@@ -21,16 +21,16 @@
},
"dependencies": {
"@apollo/server": "4.11.3",
"@nestjs/apollo": "12.2.2",
"@nestjs/apollo": "13.0.0",
"@nestjs/common": "11.0.1",
"@nestjs/core": "11.0.1",
"@nestjs/graphql": "12.2.2",
"@nestjs/graphql": "13.0.0",
"@nestjs/platform-express": "11.0.1",
"@prisma/client": "4.16.2",
"@prisma/client": "6.2.1",
"class-transformer": "0.5.1",
"class-validator": "0.14.1",
"graphql": "16.8.1",
"graphql-subscriptions": "2.0.0",
"graphql": "16.10.0",
"graphql-subscriptions": "3.0.0",
"reflect-metadata": "0.2.2",
"rimraf": "6.0.1",
"rxjs": "7.8.1"
@@ -41,11 +41,11 @@
"@nestjs/cli": "10.4.9",
"@nestjs/schematics": "10.2.3",
"@nestjs/testing": "11.0.1",
"@types/express": "4.17.21",
"@types/node": "22.10.6",
"@types/express": "5.0.0",
"@types/node": "22.10.7",
"@types/supertest": "6.0.2",
"@typescript-eslint/eslint-plugin": "5.62.0",
"@typescript-eslint/parser": "5.62.0",
"@typescript-eslint/eslint-plugin": "8.20.0",
"@typescript-eslint/parser": "8.20.0",
"eslint": "9.18.0",
"eslint-config-prettier": "10.0.1",
"eslint-plugin-import": "2.31.0",
@@ -53,7 +53,7 @@
"globals": "15.14.0",
"jest": "29.7.0",
"prettier": "3.4.2",
"prisma": "^4.15.0",
"prisma": "^6.2.1",
"supertest": "7.0.0",
"ts-jest": "29.2.5",
"ts-loader": "9.5.2",

View File

@@ -5,7 +5,7 @@
*/
/* tslint:disable */
/* eslint-disable */
export class NewPost {
title: string;
text: string;

View File

@@ -1,7 +1,7 @@
import { Resolver, Query, Mutation, Args, Subscription } from '@nestjs/graphql';
import { PostsService } from './posts.service';
import { Post, NewPost, UpdatePost } from 'src/graphql.schema';
import { Args, Mutation, Query, Resolver, Subscription } from '@nestjs/graphql';
import { PubSub } from 'graphql-subscriptions';
import { NewPost, Post, UpdatePost } from 'src/graphql.schema';
import { PostsService } from './posts.service';
const pubSub = new PubSub();
@@ -38,6 +38,6 @@ export class PostsResolvers {
@Subscription('postCreated')
postCreated() {
return pubSub.asyncIterator('postCreated');
return pubSub.asyncIterableIterator('postCreated');
}
}

View File

@@ -1,4 +1,4 @@
import { INestApplication, Injectable, OnModuleInit } from '@nestjs/common';
import { Injectable, OnModuleInit } from '@nestjs/common';
import { PrismaClient } from '@prisma/client';
@Injectable()
@@ -6,10 +6,4 @@ export class PrismaService extends PrismaClient implements OnModuleInit {
async onModuleInit() {
await this.$connect();
}
async enableShutdownHooks(app: INestApplication) {
this.$on('beforeExit', async () => {
await app.close();
});
}
}

View File

@@ -20,16 +20,16 @@
},
"dependencies": {
"@apollo/server": "4.11.3",
"@nestjs/apollo": "12.2.2",
"@nestjs/apollo": "13.0.0",
"@nestjs/common": "11.0.1",
"@nestjs/core": "11.0.1",
"@nestjs/graphql": "12.2.2",
"@nestjs/graphql": "13.0.0",
"@nestjs/platform-express": "11.0.1",
"class-transformer": "0.5.1",
"class-validator": "0.14.1",
"graphql": "16.8.1",
"graphql-query-complexity": "0.12.0",
"graphql-subscriptions": "2.0.0",
"graphql": "16.10.0",
"graphql-query-complexity": "1.0.0",
"graphql-subscriptions": "3.0.0",
"reflect-metadata": "0.2.2",
"rxjs": "7.8.1"
},
@@ -39,8 +39,8 @@
"@nestjs/cli": "10.4.9",
"@nestjs/schematics": "10.2.3",
"@nestjs/testing": "11.0.1",
"@types/express": "4.17.21",
"@types/node": "22.10.6",
"@types/express": "5.0.0",
"@types/node": "22.10.7",
"@types/supertest": "6.0.2",
"eslint": "9.18.0",
"eslint-plugin-prettier": "5.2.2",

View File

@@ -4,7 +4,7 @@
directive @upper on FIELD_DEFINITION
"""recipe """
"""recipe"""
type Recipe {
id: ID!
description: String

View File

@@ -42,6 +42,6 @@ export class RecipesResolver {
@Subscription(returns => Recipe)
recipeAdded() {
return pubSub.asyncIterator('recipeAdded');
return pubSub.asyncIterableIterator('recipeAdded');
}
}

View File

@@ -21,12 +21,12 @@
"dependencies": {
"@apollo/gateway": "2.9.3",
"@apollo/server": "4.11.3",
"@nestjs/apollo": "12.2.2",
"@nestjs/apollo": "13.0.0",
"@nestjs/common": "11.0.1",
"@nestjs/core": "11.0.1",
"@nestjs/graphql": "12.2.2",
"@nestjs/graphql": "13.0.0",
"@nestjs/platform-express": "11.0.1",
"graphql": "16.8.1",
"graphql": "16.10.0",
"graphql-tools": "9.0.11",
"reflect-metadata": "0.2.2",
"rimraf": "6.0.1",
@@ -34,18 +34,18 @@
"ts-morph": "25.0.0"
},
"devDependencies": {
"@eslint/eslintrc": "3.2.0",
"@eslint/js": "9.18.0",
"@nestjs/cli": "10.4.9",
"@nestjs/schematics": "10.2.3",
"@nestjs/testing": "11.0.1",
"@types/express": "4.17.21",
"@types/express": "5.0.0",
"@types/jest": "29.5.14",
"@types/node": "22.10.6",
"@types/node": "22.10.7",
"@types/supertest": "6.0.2",
"@typescript-eslint/eslint-plugin": "5.62.0",
"@typescript-eslint/parser": "5.62.0",
"eslint": "9.18.0",
"eslint-config-prettier": "10.0.1",
"eslint-plugin-prettier": "5.2.2",
"globals": "15.14.0",
"jest": "29.7.0",
"prettier": "3.4.2",
"supertest": "7.0.0",
@@ -54,6 +54,7 @@
"ts-node": "10.9.2",
"tsconfig-paths": "4.2.0",
"typescript": "5.7.3",
"typescript-eslint": "8.20.0",
"webpack": "5.97.1"
},
"jest": {

View File

@@ -23,12 +23,12 @@
"@apollo/gateway": "2.9.3",
"@apollo/server": "4.11.3",
"@apollo/subgraph": "2.9.3",
"@nestjs/apollo": "12.2.2",
"@nestjs/apollo": "13.0.0",
"@nestjs/common": "11.0.1",
"@nestjs/core": "11.0.1",
"@nestjs/graphql": "12.2.2",
"@nestjs/graphql": "13.0.0",
"@nestjs/platform-express": "11.0.1",
"graphql": "16.8.1",
"graphql": "16.10.0",
"graphql-tools": "9.0.11",
"reflect-metadata": "0.2.2",
"rimraf": "6.0.1",
@@ -41,9 +41,9 @@
"@nestjs/cli": "10.4.9",
"@nestjs/schematics": "10.2.3",
"@nestjs/testing": "11.0.1",
"@types/express": "4.17.21",
"@types/express": "5.0.0",
"@types/jest": "29.5.14",
"@types/node": "22.10.6",
"@types/node": "22.10.7",
"@types/supertest": "6.0.2",
"eslint": "9.18.0",
"eslint-config-prettier": "10.0.1",

View File

@@ -1,3 +1,4 @@
import { ApolloServerPluginInlineTrace } from '@apollo/server/plugin/inlineTrace';
import {
ApolloFederationDriver,
ApolloFederationDriverConfig,
@@ -8,13 +9,14 @@ import { User } from './models/user.model';
import { PostsResolver } from './posts.resolver';
import { PostsService } from './posts.service';
import { UsersResolver } from './users.resolver';
import { ApolloServerPluginInlineTrace } from '@apollo/server/plugin/inlineTrace';
@Module({
imports: [
GraphQLModule.forRoot<ApolloFederationDriverConfig>({
driver: ApolloFederationDriver,
autoSchemaFile: true,
autoSchemaFile: {
federation: 2,
},
plugins: [ApolloServerPluginInlineTrace()],
buildSchemaOptions: {
orphanedTypes: [User],

View File

@@ -22,12 +22,12 @@
"@apollo/gateway": "2.9.3",
"@apollo/server": "4.11.3",
"@apollo/subgraph": "2.9.3",
"@nestjs/apollo": "12.2.2",
"@nestjs/apollo": "13.0.0",
"@nestjs/common": "11.0.1",
"@nestjs/core": "11.0.1",
"@nestjs/graphql": "12.2.2",
"@nestjs/graphql": "13.0.0",
"@nestjs/platform-express": "11.0.1",
"graphql": "16.8.1",
"graphql": "16.10.0",
"graphql-tools": "9.0.11",
"reflect-metadata": "0.2.2",
"rimraf": "6.0.1",
@@ -40,9 +40,9 @@
"@nestjs/cli": "10.4.9",
"@nestjs/schematics": "10.2.3",
"@nestjs/testing": "11.0.1",
"@types/express": "4.17.21",
"@types/express": "5.0.0",
"@types/jest": "29.5.14",
"@types/node": "22.10.6",
"@types/node": "22.10.7",
"@types/supertest": "6.0.2",
"eslint": "9.18.0",
"eslint-config-prettier": "10.0.1",

View File

@@ -1,3 +1,4 @@
import { ApolloServerPluginInlineTrace } from '@apollo/server/plugin/inlineTrace';
import {
ApolloFederationDriver,
ApolloFederationDriverConfig,
@@ -6,14 +7,15 @@ import { Module } from '@nestjs/common';
import { GraphQLModule } from '@nestjs/graphql';
import { UsersResolver } from './users.resolver';
import { UsersService } from './users.service';
import { ApolloServerPluginInlineTrace } from '@apollo/server/plugin/inlineTrace';
@Module({
providers: [UsersResolver, UsersService],
imports: [
GraphQLModule.forRoot<ApolloFederationDriverConfig>({
driver: ApolloFederationDriver,
autoSchemaFile: true,
autoSchemaFile: {
federation: 2,
},
plugins: [ApolloServerPluginInlineTrace()],
}),
],

View File

@@ -22,13 +22,13 @@
},
"dependencies": {
"@apollo/gateway": "2.9.3",
"@apollo/server": "^4.7.4",
"@nestjs/apollo": "12.2.2",
"@apollo/server": "^4.11.3",
"@nestjs/apollo": "13.0.0",
"@nestjs/common": "11.0.1",
"@nestjs/core": "11.0.1",
"@nestjs/graphql": "12.2.2",
"@nestjs/graphql": "13.0.0",
"@nestjs/platform-express": "11.0.1",
"graphql": "16.8.1",
"graphql": "16.10.0",
"graphql-tools": "9.0.11",
"reflect-metadata": "0.2.2",
"rimraf": "6.0.1",
@@ -41,9 +41,9 @@
"@nestjs/cli": "10.4.9",
"@nestjs/schematics": "10.2.3",
"@nestjs/testing": "11.0.1",
"@types/express": "4.17.21",
"@types/express": "5.0.0",
"@types/jest": "29.5.14",
"@types/node": "22.10.6",
"@types/node": "22.10.7",
"@types/supertest": "6.0.2",
"eslint": "9.18.0",
"eslint-config-prettier": "10.0.1",

View File

@@ -22,14 +22,14 @@
},
"dependencies": {
"@apollo/gateway": "2.9.3",
"@apollo/server": "^4.7.4",
"@apollo/server": "^4.11.3",
"@apollo/subgraph": "2.9.3",
"@nestjs/apollo": "12.2.2",
"@nestjs/apollo": "13.0.0",
"@nestjs/common": "11.0.1",
"@nestjs/core": "11.0.1",
"@nestjs/graphql": "12.2.2",
"@nestjs/graphql": "13.0.0",
"@nestjs/platform-express": "11.0.1",
"graphql": "16.8.1",
"graphql": "16.10.0",
"graphql-tools": "9.0.11",
"reflect-metadata": "0.2.2",
"rimraf": "6.0.1",
@@ -42,9 +42,9 @@
"@nestjs/cli": "10.4.9",
"@nestjs/schematics": "10.2.3",
"@nestjs/testing": "11.0.1",
"@types/express": "4.17.21",
"@types/express": "5.0.0",
"@types/jest": "29.5.14",
"@types/node": "22.10.6",
"@types/node": "22.10.7",
"@types/supertest": "6.0.2",
"eslint": "9.18.0",
"eslint-config-prettier": "10.0.1",

View File

@@ -13,4 +13,5 @@ extend type User @key(fields: "id") {
extend type Query {
getPosts: [Post]
findPost(id: ID!): Post
}

View File

@@ -21,14 +21,14 @@
},
"dependencies": {
"@apollo/gateway": "2.9.3",
"@apollo/server": "^4.7.4",
"@apollo/server": "^4.11.3",
"@apollo/subgraph": "2.9.3",
"@nestjs/apollo": "12.2.2",
"@nestjs/apollo": "13.0.0",
"@nestjs/common": "11.0.1",
"@nestjs/core": "11.0.1",
"@nestjs/graphql": "12.2.2",
"@nestjs/graphql": "13.0.0",
"@nestjs/platform-express": "11.0.1",
"graphql": "16.8.1",
"graphql": "16.10.0",
"graphql-tools": "9.0.11",
"reflect-metadata": "0.2.2",
"rimraf": "6.0.1",
@@ -36,15 +36,15 @@
"ts-morph": "25.0.0"
},
"devDependencies": {
"@eslint/eslintrc": "3.2.0",
"@eslint/js": "9.18.0",
"@nestjs/cli": "10.4.9",
"@nestjs/schematics": "10.2.3",
"@nestjs/testing": "11.0.1",
"@types/express": "4.17.21",
"@types/express": "5.0.0",
"@types/jest": "29.5.14",
"@types/node": "22.10.6",
"@types/node": "22.10.7",
"@types/supertest": "6.0.2",
"@typescript-eslint/eslint-plugin": "5.62.0",
"@typescript-eslint/parser": "5.62.0",
"eslint": "9.18.0",
"eslint-config-prettier": "10.0.1",
"eslint-plugin-prettier": "5.2.2",
@@ -55,7 +55,8 @@
"ts-loader": "9.5.2",
"ts-node": "10.9.2",
"tsconfig-paths": "4.2.0",
"typescript": "5.7.3"
"typescript": "5.7.3",
"typescript-eslint": "8.20.0"
},
"jest": {
"moduleFileExtensions": [

View File

@@ -21,12 +21,12 @@
"dependencies": {
"@nestjs/common": "11.0.1",
"@nestjs/core": "11.0.1",
"@nestjs/graphql": "12.2.2",
"@nestjs/mercurius": "12.2.2",
"@nestjs/graphql": "13.0.0",
"@nestjs/mercurius": "13.0.0",
"@nestjs/platform-fastify": "11.0.1",
"class-transformer": "0.5.1",
"class-validator": "0.14.1",
"graphql": "16.8.1",
"graphql": "16.10.0",
"mercurius": "16.0.1",
"reflect-metadata": "0.2.2",
"rxjs": "7.8.1"

View File

@@ -16,7 +16,7 @@ scalar Date
type Query {
recipe(id: String!): Recipe!
recipes(skip: Int = 0, take: Int = 25): [Recipe!]!
recipes(skip: Int! = 0, take: Int! = 25): [Recipe!]!
}
type Mutation {