1
0

client-schema.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import { makeExecutableSchema } from '@graphql-tools/schema';
  2. import fs from 'fs';
  3. import path from 'path';
  4. const CLIENT_SCHEMA_FILE = '../../packages/admin-ui/src/lib/core/src/data/client-state/client-types.graphql';
  5. const LANGUAGE_CODE_FILE = '../../packages/core/src/api/schema/common/language-code.graphql';
  6. const AUTH_TYPE_FILE = '../../packages/core/src/api/schema/common/auth.type.graphql';
  7. function loadGraphQL(file: string): string {
  8. const filePath = path.join(__dirname, file);
  9. return fs.readFileSync(filePath, 'utf8');
  10. }
  11. /**
  12. * Augments the client schema (used by apollo-link-state) with missing
  13. * definitions, to allow the codegen step to work correctly.
  14. * See: https://github.com/dotansimha/graphql-code-generator/issues/583
  15. */
  16. function getClientSchema() {
  17. const clientDirective = `
  18. directive @client on FIELD
  19. `;
  20. const clientSchemaString = loadGraphQL(CLIENT_SCHEMA_FILE);
  21. const languageCodeString = loadGraphQL(LANGUAGE_CODE_FILE);
  22. const authTypeString = loadGraphQL(AUTH_TYPE_FILE);
  23. const permissionTypeString = `enum Permission { Placeholder }`;
  24. const schema = makeExecutableSchema({
  25. typeDefs: [
  26. clientSchemaString,
  27. clientDirective,
  28. languageCodeString,
  29. authTypeString,
  30. permissionTypeString,
  31. ],
  32. });
  33. return schema;
  34. }
  35. export default getClientSchema();