Graphql tools - mergeTypeDefs sort alphabetically

443 Views Asked by At

I'm using the following code to merge 2 typesDefs to one:

import { mergeTypeDefs } from '@graphql-tools/merge';
import topicsTypes from '../modules/topics/typeDefs';
import contentTypes from '../modules/content/typeDefs';

const types = [contentTypes, topicsTypes];

export default mergeTypeDefs(types)

When I run graphql-schema-linter I get an error:

22:1 The fields of object type Query should be sorted in alphabetical order. Expected sorting: contentAccessTokenByUUID, documentContent, documentTopics type-fields-sorted-alphabetically

I tried changing the order of the types in the array to [topicsTypes, contentTypes];

But I get the same error, how can I force mergeTypeDefs to merge the defs alphabetically?

1

There are 1 best solutions below

0
Zee On

Try to import your schemas as shown below
Depending on your file extension edit the following

     import { mergeTypeDefs } from '@graphql-tools/merge';
     import { loadFilesSync } from '@graphql-tools/load-files';
        
     const typesArray = loadFilesSync('./schema', {
              extensions: ['gql'],
            });
     const typeDefs = mergeTypeDefs(typesArray, { throwOnConflict: true, sort: true });

     export default typeDefs;

If you want to check out the doc New mergeTypeDefs-routine from https://www.graphql-tools.com/docs/migration-from-merge-graphql-schemas/

Also might be helpful to check out this https://www.graphql-tools.com/docs/api/interfaces/merge_src.Config#throwonconflict