client-schema.ts 1.4 KB

12345678910111213141516171819202122232425262728293031323334
  1. import fs from 'fs';
  2. import { makeExecutableSchema } from 'graphql-tools';
  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/type/auth.type.graphql';
  7. const PERMISSION_TYPE_FILE = '../../packages/core/src/api/schema/common/permission.graphql';
  8. function loadGraphQL(file: string): string {
  9. const filePath = path.join(__dirname, file);
  10. return fs.readFileSync(filePath, 'utf8');
  11. }
  12. /**
  13. * Augments the client schema (used by apollo-link-state) with missing
  14. * definitions, to allow the codegen step to work correctly.
  15. * See: https://github.com/dotansimha/graphql-code-generator/issues/583
  16. */
  17. function getClientSchema() {
  18. const clientDirective = `
  19. directive @client on FIELD
  20. `;
  21. const clientSchemaString = loadGraphQL(CLIENT_SCHEMA_FILE);
  22. const languageCodeString = loadGraphQL(LANGUAGE_CODE_FILE);
  23. const authTypeString = loadGraphQL(AUTH_TYPE_FILE);
  24. const permissionTypeString = loadGraphQL(PERMISSION_TYPE_FILE);
  25. const schema = makeExecutableSchema({
  26. typeDefs: [clientSchemaString, clientDirective, languageCodeString, authTypeString, permissionTypeString],
  27. });
  28. return schema;
  29. }
  30. export default getClientSchema();