client-schema.ts 1.0 KB

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