Skip to content

Commit

Permalink
feat(graphql-tag-pluck): keep locationOffset and return graphql-js So…
Browse files Browse the repository at this point in the history
…urce instead of string
  • Loading branch information
ardatan committed Jul 1, 2021
1 parent 9300d12 commit 34c31de
Show file tree
Hide file tree
Showing 8 changed files with 247 additions and 108 deletions.
6 changes: 6 additions & 0 deletions .changeset/slimy-rice-exercise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@graphql-tools/graphql-tag-pluck': major
---

BREAKING CHANGE
- feat(graphql-tag-pluck): keep locationOffset and return graphql-js Source instead of string
13 changes: 5 additions & 8 deletions packages/graphql-tag-pluck/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { getExtNameFromFilePath } from './libs/extname';
import createVisitor, { PluckedContent } from './visitor';
import traverse from '@babel/traverse';
import { freeText } from './utils';
import { Source } from 'graphql';

/**
* Additional options for determining how a file is parsed.
Expand Down Expand Up @@ -128,7 +129,7 @@ export const gqlPluckFromCodeString = async (
filePath: string,
code: string,
options: GraphQLTagPluckOptions = {}
): Promise<string> => {
): Promise<Source[]> => {
validate({ code, options });

const fileExt = extractExtension(filePath);
Expand All @@ -137,9 +138,7 @@ export const gqlPluckFromCodeString = async (
code = await pluckVueFileScript(code);
}

return parseCode({ code, filePath, options })
.map(t => t.content)
.join('\n\n');
return parseCode({ code, filePath, options }).map(t => new Source(t.content, filePath, t.loc.start));
};

/**
Expand All @@ -155,7 +154,7 @@ export const gqlPluckFromCodeStringSync = (
filePath: string,
code: string,
options: GraphQLTagPluckOptions = {}
): string => {
): Source[] => {
validate({ code, options });

const fileExt = extractExtension(filePath);
Expand All @@ -164,9 +163,7 @@ export const gqlPluckFromCodeStringSync = (
code = pluckVueFileScriptSync(code);
}

return parseCode({ code, filePath, options })
.map(t => t.content)
.join('\n\n');
return parseCode({ code, filePath, options }).map(t => new Source(t.content, filePath, t.loc.start));
};

export function parseCode({
Expand Down
Loading

0 comments on commit 34c31de

Please sign in to comment.