josemarluedke / glimmer-apollo

Ember and Glimmer integration for Apollo Client.
https://glimmer-apollo.com
MIT License
38 stars 14 forks source link

Unable to import schema.graphql using Ember 3.28.4 #52

Closed xomaczar closed 2 years ago

xomaczar commented 3 years ago

I am trying to use this addon in an ember app (ember@3.28.4) with ember-auto-import@2.2.3. When I am attempting to import schema.graphql anywhere in the app, it fails with "could not find module". Am I missing something

josemarluedke commented 3 years ago

Hi there. Glimmer Apollo does not include any file processing like importing .graphql files.

You can take a look at using Webpack with Embroider as that is the best moving forward option. But you can also use broccoli-graphql-filter with an in-repo addon.

Here is the code for that:

index.js

'use strict';

module.exports = {
  name: require('./package').name,

  isDevelopingAddon() {
    return true;
  },

  setupPreprocessorRegistry(type, registry) {
    if (type === 'parent') {
      registry.add('js', {
        name: require('./package').name,
        ext: 'graphql',
        toTree(tree) {
          const GraphQLFilter = require('broccoli-graphql-filter');

          return new GraphQLFilter(tree, {
            keepExtension: true
          });
        }
      });
    }
  }
};

package.json

{
  "name": "graphql-loader",
  "dependencies": {
    "broccoli-graphql-filter": "*"
  },
  "keywords": [
    "ember-addon"
  ],
  "ember-addon": {
    "before": [
      "ember-cli-babel"
    ]
  }
}

There are a few things we can do here to avoid this confusion, add documentation about this. We can also create an ember addon for non-embroider to consume .graphql files.

josemarluedke commented 2 years ago

I have created a super simple addon that does this:

https://github.com/josemarluedke/ember-cli-graphql-loader

There is no docs, just add it to your project and it should be good to go.