relay-compiler should use directory name as prefix if the filename is index.js

Created on 11 May 2017  路  3Comments  路  Source: facebook/relay

It's a pretty common pattern in node to replace a growing file with a directory and index.js, such that existing imports continue to work. When this is the case, relay-compiler currently forces the prefix to be "index" instead of "Test":

import test from './Test';

// Works from ./Test.js
graphql`
    query TestQuery($id: ID!) {
        node (id: $id) {
            id
        }
    }
`;

// Fails from ./Test/index.js
// FindGraphQLTags: Operation names in graphql tags must be prefixed with the module name
// and end in "Mutation", "Query", or "Subscription". Got `TestQuery` in module `index`.
graphql`
    query TestQuery($id: ID!) {
        node (id: $id) {
            id
        }
    }
`;

If the current module name is index.js, I would expect that it accept the directory name as the prefix for such queries.

Most helpful comment

Fix coming

All 3 comments

Fix coming

Using index.js for component is not a good idea. When an error occur it will throw that happened on index.js and you need to figure it out the path of index.js. It is bad to find the file on IDE as well

@sibelius - typically stack traces include full file paths. The IDE tabs/find is a reasonable concern, but maybe not enough to warrant not supporting it.

Was this page helpful?
0 / 5 - 0 ratings