nicolasdao / schemaglue

Naturally breaks down your monolithic graphql schema into bits and pieces and then glue them back together.
BSD 3-Clause "New" or "Revised" License
116 stars 13 forks source link

How to import schema.graphql when build production mode #17

Closed huythanhjv05 closed 3 years ago

huythanhjv05 commented 5 years ago

I had structured my code using your library . It has been working normally utils i got an issues when i want to deploy it on my server . I could not import schema.graphql extension . i used typescript for build. Need your advice !!! Thank you very much

nicolasdao commented 5 years ago

Hi @huythanhjv05,

First and foremost, thanks for using our library. To assist you, we need to know a bit more about your project. Would you mind to provide:

  1. The schemaglue version you're using.
  2. The exact error message you receive when you're deploying your code to your server.
  3. A code sample that could help us to diagnose your issue.
rener172846 commented 5 years ago

I have the same problem. I'm using schemaglue version 4.0.2 and typescript. And I have defined schema as the doc, and it works well on typescript debug mode.

const { schema, resolver } = glue('src/graphql', { mode: 'ts' })

My problem is after build project (the build directory is "./dist"), it still use original directory which is typescript codes 'src/graphql'. I think it should be changed to 'dist/graphql' Here are my codes for graphql:

/src/graphql/index.ts

import glue from 'schemaglue';
export { schemaDirectives } from './directives';
export const { schema, resolver } = glue('src/graphql', { mode: 'ts' });

/dist/graphql/index.js

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
var _a;
Object.defineProperty(exports, "__esModule", { value: true });
const schemaglue_1 = __importDefault(require("schemaglue"));
var directives_1 = require("./directives");
exports.schemaDirectives = directives_1.schemaDirectives;
_a = schemaglue_1.default('src/graphql', { mode: 'ts' }), exports.schema = _a.schema, exports.resolver = _a.resolver;
//# sourceMappingURL=index.js.map

As you can see the compiled js codes still reference ts codes and it occurs SyntaxError. Please help me to fix that

huythanhjv05 commented 5 years ago

thanks @rener172846 . the same problem to me . Thank for your explanation

huythanhjv05 commented 5 years ago

@rener172846 I have tried to find out a work around solution by copy the *.graphql in build script "build:copy": "copyfiles -u 1 src/graphql/*/.graphql dist", "build:server": "rimraf dist && tsc", "build": "npm install && concurrently --kill-others-on-fail \"npm run build:server\" \"npm run build:copy\"" Need copyfiles library in there

nicolasdao commented 5 years ago

Hi @ilgooz,

Do you think you could have a look at this TypeScript issue? Because you implemented the TS support, I think you might help. Let me know if you can.

Thanks a lot in advance.

josevsalina commented 4 years ago

Same issue here! this is still open?

nicolasdao commented 4 years ago

Hi @josevsp , @ilgooz , @rener172846 and @huythanhjv05 ,

This issue is not due to Schemaglue. It relates to the lack of support of .graphql files by Typescript. Please have a look at this article that explains how to use Webpack to add support for .graphql files with Typescript: https://dev.to/open-graphql/how-to-resolve-import-for-the-graphql-file-with-typescript-and-webpack-35lf

However, there is a way to use Schemaglue with typescript without going into all the complexity of setting up Webpack, but you will lose in readability. The solution is to replace you GraphQL files (.graphql) with plain .js files. I've documented that approach in the README file here https://github.com/nicolasdao/schemaglue#typescript-support.

Hope this helps, and thanks again for your support and your patience.

Cheers,

Nic