Skip to content

Commit ade4e70

Browse files
committed
feat(graphql-tag-pluck): keep locationOffset and return graphql-js Source instead of string
1 parent 9300d12 commit ade4e70

File tree

6 files changed

+123
-107
lines changed

6 files changed

+123
-107
lines changed

.changeset/slimy-rice-exercise.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@graphql-tools/graphql-tag-pluck': major
3+
---
4+
5+
BREAKING CHANGE
6+
- feat(graphql-tag-pluck): keep locationOffset and return graphql-js Source instead of string

packages/graphql-tag-pluck/src/index.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { getExtNameFromFilePath } from './libs/extname';
44
import createVisitor, { PluckedContent } from './visitor';
55
import traverse from '@babel/traverse';
66
import { freeText } from './utils';
7+
import { Source } from 'graphql';
78

89
/**
910
* Additional options for determining how a file is parsed.
@@ -128,7 +129,7 @@ export const gqlPluckFromCodeString = async (
128129
filePath: string,
129130
code: string,
130131
options: GraphQLTagPluckOptions = {}
131-
): Promise<string> => {
132+
): Promise<Source[]> => {
132133
validate({ code, options });
133134

134135
const fileExt = extractExtension(filePath);
@@ -137,9 +138,7 @@ export const gqlPluckFromCodeString = async (
137138
code = await pluckVueFileScript(code);
138139
}
139140

140-
return parseCode({ code, filePath, options })
141-
.map(t => t.content)
142-
.join('\n\n');
141+
return parseCode({ code, filePath, options }).map(t => new Source(t.content, filePath, t.loc.start));
143142
};
144143

145144
/**
@@ -155,7 +154,7 @@ export const gqlPluckFromCodeStringSync = (
155154
filePath: string,
156155
code: string,
157156
options: GraphQLTagPluckOptions = {}
158-
): string => {
157+
): Source[] => {
159158
validate({ code, options });
160159

161160
const fileExt = extractExtension(filePath);
@@ -164,9 +163,7 @@ export const gqlPluckFromCodeStringSync = (
164163
code = pluckVueFileScriptSync(code);
165164
}
166165

167-
return parseCode({ code, filePath, options })
168-
.map(t => t.content)
169-
.join('\n\n');
166+
return parseCode({ code, filePath, options }).map(t => new Source(t.content, filePath, t.loc.start));
170167
};
171168

172169
export function parseCode({

0 commit comments

Comments
 (0)