From 282251102c1284a1e0ede98e2b498a32e3f99c1a Mon Sep 17 00:00:00 2001 From: Dylan Aubrey Date: Wed, 16 Nov 2022 11:01:00 +0000 Subject: [PATCH 1/2] docs: add GraphQLBox client and server to docs --- .../code/language-support/javascript/client/graphql-box.md | 7 +++++++ .../code/language-support/javascript/server/graphql-box.md | 7 +++++++ 2 files changed, 14 insertions(+) create mode 100644 src/content/code/language-support/javascript/client/graphql-box.md create mode 100644 src/content/code/language-support/javascript/server/graphql-box.md diff --git a/src/content/code/language-support/javascript/client/graphql-box.md b/src/content/code/language-support/javascript/client/graphql-box.md new file mode 100644 index 0000000000..9b7d1f9603 --- /dev/null +++ b/src/content/code/language-support/javascript/client/graphql-box.md @@ -0,0 +1,7 @@ +--- +name: GraphQLBox client +description: An extensible GraphQL client with modules for react, caching, request parsing, web workers, websockets and more... +url: https://github.com/badbatch/graphql-box +github: badbatch/graphql-box +npm: "@graphql-box/client" +--- diff --git a/src/content/code/language-support/javascript/server/graphql-box.md b/src/content/code/language-support/javascript/server/graphql-box.md new file mode 100644 index 0000000000..cf7aa7db20 --- /dev/null +++ b/src/content/code/language-support/javascript/server/graphql-box.md @@ -0,0 +1,7 @@ +--- +name: GraphQLBox server +description: An extensible GraphQL server with modules for caching, request parsing, debugging, subscriptions and more... +url: https://github.com/badbatch/graphql-box +github: badbatch/graphql-box +npm: "@graphql-box/server" +--- From 3eedd3772784622d10a438afac8e3f1113b58464 Mon Sep 17 00:00:00 2001 From: Dylan Aubrey Date: Wed, 16 Nov 2022 12:15:34 +0000 Subject: [PATCH 2/2] docs: update examples --- .../javascript/client/graphql-box.md | 53 ++++++++++++++++++ .../javascript/server/graphql-box.md | 55 +++++++++++++++++++ 2 files changed, 108 insertions(+) diff --git a/src/content/code/language-support/javascript/client/graphql-box.md b/src/content/code/language-support/javascript/client/graphql-box.md index 9b7d1f9603..7f731a59e2 100644 --- a/src/content/code/language-support/javascript/client/graphql-box.md +++ b/src/content/code/language-support/javascript/client/graphql-box.md @@ -5,3 +5,56 @@ url: https://github.com/badbatch/graphql-box github: badbatch/graphql-box npm: "@graphql-box/client" --- + +The example below installs and initializes the GraphQLBox client with a persisted cache and debugging enabled. + +```bash +npm install @graphql-box/core @graphql-box/client @graphql-box/request-parser @graphql-box/cache-manager @graphql-box/debug-manager @graphql-box/fetch-manager @graphql-box/helpers @cachemap/core @cachemap/reaper @cachemap/indexed-db @cachemap/constants @cachemap/types +``` + +```javascript +import Cachemap from "@cachemap/core"; +import indexedDB from "@cachemap/indexed-db"; +import reaper from "@cachemap/reaper"; +import CacheManager from "@graphql-box/cache-manager"; +import Client from "@graphql-box/client"; +import DebugManager from "@graphql-box/debug-manager"; +import FetchManager from "@graphql-box/fetch-manager"; +import RequestParser from "@graphql-box/request-parser"; +import introspection from "./introspection-query"; + +const requestManager = new FetchManager({ + apiUrl: "/api/graphql", + batchRequests: true, + logUrl: "/log/graphql", +}); + +const client = new Client({ + cacheManager: new CacheManager({ + cache: new Cachemap({ + name: "client-cache", + reaper: reaper({ interval: 300000 }), + store: indexedDB(/* configure */), + }), + cascadeCacheControl: true, + typeCacheDirectives: { + // Add any type specific cache control directives in the format: + // TypeName: "public, max-age=3", + }, + }), + debugManager: new DebugManager({ + environment: "client", + log: (message, data, logLevel) => { + requestManager.log(message, data, logLevel); + }, + name: "CLIENT", + performance: self.performance, + }), + requestManager, + requestParser: new RequestParser({ introspection }), +}); + +// Meanwhile... somewhere else in your code + +const { data, errors } = await client.request(queryOrMutation); +``` diff --git a/src/content/code/language-support/javascript/server/graphql-box.md b/src/content/code/language-support/javascript/server/graphql-box.md index cf7aa7db20..db2bca7c95 100644 --- a/src/content/code/language-support/javascript/server/graphql-box.md +++ b/src/content/code/language-support/javascript/server/graphql-box.md @@ -5,3 +5,58 @@ url: https://github.com/badbatch/graphql-box github: badbatch/graphql-box npm: "@graphql-box/server" --- + +The example below installs and initializes the GraphQLBox server with a persisted cache and debugging enabled. + +```bash +npm install @graphql-box/core @graphql-box/server @graphql-box/client @graphql-box/request-parser @graphql-box/cache-manager @graphql-box/debug-manager @graphql-box/execute @graphql-box/helpers @cachemap/core @cachemap/reaper @cachemap/redis @cachemap/constants @cachemap/types +``` + +```javascript +import Cachemap from "@cachemap/core"; +import redis from "@cachemap/redis"; +import reaper from "@cachemap/reaper"; +import CacheManager from "@graphql-box/cache-manager"; +import Client from "@graphql-box/client"; +import DebugManager from "@graphql-box/debug-manager"; +import Execute from "@graphql-box/execute"; +import RequestParser from "@graphql-box/request-parser"; +import Server from "@graphql-box/server"; +import { makeExecutableSchema } from "@graphql-tools/schema"; +import { performance } from "perf_hooks"; +import { schemaResolvers, schemaTypeDefs } from "./schema"; +import logger from './logger'; + +const schema = makeExecutableSchema({ typeDefs: schemaTypeDefs, resolvers: schemaResolvers }); + +const server = new Server({ + client: new Client({ + cacheManager: new CacheManager({ + cache: new Cachemap({ + name: "server-cache", + reaper: reaper({ interval: 300000 }), + store: redis(/* configure */), + }), + cascadeCacheControl: true, + typeCacheDirectives: { + // Add any type specific cache control directives in the format: + // TypeName: "public, max-age=3", + }, + }), + debugManager: new DebugManager({ + environment: "server", + log: (...args) => { + logger.log(...args); + }, + name: "SERVER", + performance, + }), + requestManager: new Execute({ schema }), + requestParser: new RequestParser({ schema }), + }), +}); + +// Meanwhile... somewhere else in your code + +app.use("api/graphql", graphqlServer.request()); +```