Skip to content

Commit

Permalink
fix: ensure next loader will be used if first one does not yield a re…
Browse files Browse the repository at this point in the history
…sult
  • Loading branch information
n1ru4l committed Jul 7, 2021
1 parent 44723c5 commit 5c01269
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
11 changes: 9 additions & 2 deletions packages/load/src/load-typedefs/load-file.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Source, Maybe } from '@graphql-tools/utils';
import { Source, Maybe, isSome } from '@graphql-tools/utils';
import { env } from 'process';
import { LoadTypedefsOptions } from '../load-typedefs';

Expand All @@ -15,6 +15,9 @@ export async function loadFile(pointer: string, options: LoadTypedefsOptions): P

if (canLoad) {
const loadedValue = await loader.load(pointer, options);
if (!isSome(loadedValue) || loadedValue.length === 0) {
continue;
}
return loadedValue;
}
} catch (error) {
Expand All @@ -41,7 +44,11 @@ export function loadFileSync(pointer: string, options: LoadTypedefsOptions): May

if (canLoad) {
// We check for the existence so it is okay to force non null
return loader.loadSync!(pointer, options);
const loadedValue = loader.loadSync!(pointer, options);
if (!isSome(loadedValue) || loadedValue.length === 0) {
continue;
}
return loadedValue;
}
} catch (error) {
if (env['DEBUG']) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,5 +133,12 @@ describe('documentsFromGlob', () => {
});
expect(result.length).toBe(1);
});
test(`should try next loader if first one fails`, async () => {
const glob = join(__dirname, './test-with-brackets/', '**/*.ts');
const result = await load(glob, {
loaders: [new GraphQLFileLoader(), new CodeFileLoader()],
});
expect(result.length).toBe(1);
})
})
});

0 comments on commit 5c01269

Please sign in to comment.