Browse Source

query node - GraphQL Playground dependency overload II

ondratra 3 years ago
parent
commit
cc5a6c4242

+ 1 - 1
package.json

@@ -37,7 +37,7 @@
     "@polkadot/util": "^6.0.5",
     "@polkadot/util-crypto": "^6.0.5",
     "@polkadot/wasm-crypto": "^4.0.2",
-    "@apollographql/graphql-playground-html": "https://gitpkg.now.sh/ondratra/graphql-playground/packages/graphql-playground-html?templates_extension_with_build",
+    "warthog": "https://github.com/ondratra/warthog/releases/download/v2.23.1/warthog-v2.23.1.tgz",
     "babel-core": "^7.0.0-bridge.0",
     "typescript": "^3.9.7",
     "bn.js": "^5.1.2",

+ 2 - 1
query-node/generated/graphql-server/src/index.ts

@@ -8,6 +8,7 @@ import { Logger } from '../src/logger';
 
 import { buildServerSchema, getServer } from './server';
 import { startPgSubsribers } from './pubsub';
+import { queryTemplates } from './queryTemplates'
 
 
 class CustomNamingStrategy extends SnakeNamingStrategy {
@@ -22,7 +23,7 @@ class CustomNamingStrategy extends SnakeNamingStrategy {
 async function bootstrap() {
   await loadConfig();
 
-  const server = getServer({}, { namingStrategy: new CustomNamingStrategy() });
+  const server = getServer({ queryTemplates }, { namingStrategy: new CustomNamingStrategy() });
 
   // Create database tables. Warthog migrate command does not support CustomNamingStrategy thats why
   // we have this code

+ 52 - 0
query-node/generated/graphql-server/src/queryTemplates.ts

@@ -0,0 +1,52 @@
+import { IQueryTemplate, queryTemplateUtils } from '@apollographql/graphql-playground-react/lib/components/Playground/QueryTemplates/templateUtils'
+
+const exampleDate = `"2018-01-31 23:59"`
+
+export const queryTemplates: IQueryTemplate[] = [
+  ...queryTemplateUtils.getOneGetAllTemplates('video', 'videos', 'videos'),
+  {
+    title: 'Featured videos',
+    description: 'Get all featured videos.',
+    query: `query {
+      ${queryTemplateUtils.descriptionMarker}
+      videos(where: { isFeatured_eq: true }) { ${queryTemplateUtils.allPropsMarker} }
+    }`,
+  }, {
+    title: 'All recent videos',
+    description: 'Get all videos after created or updated after the given date.',
+    query: `query {
+      ${queryTemplateUtils.descriptionMarker}
+      videos(where: {
+        createdAt_gt: ${exampleDate},
+        updatedAt_gt: ${exampleDate},
+      }) { ${queryTemplateUtils.allPropsMarker} }
+    }`,
+  },
+
+  ...queryTemplateUtils.getOneGetAllTemplates('video category', 'video categories', 'videoCategories'),
+  {
+    title: `All videos in category`,
+    description: `Get all videos associated with the given video category.`,
+    query: `query {
+      ${queryTemplateUtils.descriptionMarker}
+      videos(where: { categoryId_eq: 1 }) { ${queryTemplateUtils.allPropsMarker} }
+    }`,
+  },
+  ...queryTemplateUtils.getOneGetAllTemplates('channel', 'channels', 'channels'),
+  ...queryTemplateUtils.getOneGetAllTemplates('channel category', 'channels categories', 'channelCategories'),
+
+  {
+    title: `Channel's videos`,
+    description: `Get all videos associated with the given channel.`,
+    query: `query {
+      ${queryTemplateUtils.descriptionMarker}
+      videos(where: { channelId_eq: 1 }) { ${queryTemplateUtils.allPropsMarker} }
+    }`,
+  },
+
+  ...queryTemplateUtils.getOneGetAllTemplates('asset', 'assets', 'dataObjects'),
+  ...queryTemplateUtils.getOneGetAllTemplates('membership', 'memberships', 'memberships'),
+
+  ...queryTemplateUtils.getOneGetAllTemplates('curator group', 'curator groups', 'curatorGroups'),
+  ...queryTemplateUtils.getOneGetAllTemplates('worker', 'workers', 'workers'),
+].map(queryTemplateUtils.formatQuery)

File diff suppressed because it is too large
+ 509 - 34
yarn.lock


Some files were not shown because too many files changed in this diff