From 30cd084623a9577ec72a672c3921e4396d7fd301 Mon Sep 17 00:00:00 2001 From: uhyo Date: Mon, 9 Oct 2023 15:08:47 +0900 Subject: [PATCH] docs(blog): add runtime example --- .../src/app/blog/_articles/release-1.3.tsx | 54 +++++++++++++++++-- 1 file changed, 50 insertions(+), 4 deletions(-) diff --git a/website/src/app/blog/_articles/release-1.3.tsx b/website/src/app/blog/_articles/release-1.3.tsx index af7fdd82..d05f78d3 100644 --- a/website/src/app/blog/_articles/release-1.3.tsx +++ b/website/src/app/blog/_articles/release-1.3.tsx @@ -96,6 +96,51 @@ export default new GraphQLSchema({ extensions.codegenScalarType metadata. We are not aware of any other libraries that provide such metadata though.

+

+ At runtime, you should reuse the GraphQLSchema instance you + supplied to nitrogql. To do so, merge that instance with the other parts + of your schema and your resolver implementations.{" "} + + @graphql-tools/schema + {" "} + provides a convenient way to do so. For example: +

+ + {`import { mergeSchemas } from "@graphql-tools/schema"; + +// GraphQLSchema object for scalars +import schema from "../../schema/scalar"; + +// Generated by nitrogql +import { schema as typeDefs } from "@/generated/graphql"; +import { Resolvers } from "@/generated/resolvers"; + +type Context = {}; +const resolvers: Resolvers<{}> = { + // ... +}; + +const server = new ApolloServer({ + schema: mergeSchemas({ + schemas: [schema], + typeDefs, + resolvers, + }), +});`} + +

+ See{" "} + + our Next.js example + {" "} + for a working example. +

Conclusion

@@ -107,10 +152,11 @@ export default new GraphQLSchema({

- Having a single source of truth for custom scalar types is always a good - thing. It is good idea for libraries to provide such metadata so that - the runtime implementation and the TypeScript type definition are always - in sync. This release is a significant step towards that direction. + Having a single source of truth is always preferable. Custom scalar + types are no exception. Therefore, it is good idea for libraries to + provide such metadata so that the runtime implementation and the + TypeScript type definition are always in sync. This release is a + significant step towards that direction.