Skip to content

Commit cef9813

Browse files
committedJul 1, 2020
Accept output of generateFragments in compileNodeQueries + prettier fixes
1 parent a9d3359 commit cef9813

File tree

4 files changed

+29
-9
lines changed

4 files changed

+29
-9
lines changed
 

‎.prettierignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
package.json
2+
package-lock.json

‎.prettierrc

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"arrowParens": "avoid",
3+
"semi": false
4+
}

‎README.md

+12-5
Original file line numberDiff line numberDiff line change
@@ -908,7 +908,7 @@ function providePostDescriptionArguments(field, parentType) {
908908
generateDefaultFragments({
909909
schema,
910910
gatsbyNodeTypes,
911-
defaultArgumentValues: [providePostDescriptionArguments]
911+
defaultArgumentValues: [providePostDescriptionArguments],
912912
})
913913
```
914914

@@ -934,10 +934,14 @@ interface ICompileNodeDocumentsArgs {
934934
schema: GraphQLSchema
935935
gatsbyNodeTypes: IGatsbyNodeConfig[]
936936
gatsbyFieldAliases?: IGatsbyFieldAliases
937-
customFragments: Array<GraphQLSource>
937+
customFragments:
938+
| Array<GraphQLSource | string>
939+
| Map<RemoteTypeName, GraphQLSource | string>
938940
}
939941
940-
function compileNodeQueries(args: ICompileNodeDocumentsArgs): Map<RemoteTypeName, DocumentNode>
942+
function compileNodeQueries(
943+
args: ICompileNodeDocumentsArgs
944+
): Map<RemoteTypeName, DocumentNode>
941945
```
942946

943947
### Schema customization tools
@@ -971,10 +975,14 @@ that were updated in the remote API since the last Gatsby build.
971975
See dedicated section [sourcing changes](#sourcing-changes-delta) for details.
972976

973977
```ts
974-
async function sourceNodeChanges(config: ISourcingConfig, delta: ISourceChanges): Promise<void>
978+
async function sourceNodeChanges(
979+
config: ISourcingConfig,
980+
delta: ISourceChanges
981+
): Promise<void>
975982
```
976983

977984
Related types:
985+
978986
```ts
979987
interface IRemoteId {
980988
[remoteIdField: string]: unknown
@@ -999,7 +1007,6 @@ interface ISourceChanges {
9991007
}
10001008
```
10011009

1002-
10031010
## TODO:
10041011

10051012
- [ ] Allow complex nested `remoteIdFields`

‎src/compile-node-queries/compile-node-queries.ts

+11-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { GraphQLSchema, DocumentNode, parse } from "graphql"
2+
import { flatMap } from "lodash"
23
import { defaultGatsbyFieldAliases } from "../config/default-gatsby-field-aliases"
34
import { compileNodeDocument } from "./compile-node-document"
45
import { compileNodeFragments } from "./compile-node-fragments"
@@ -14,7 +15,9 @@ interface ICompileNodeDocumentsArgs {
1415
schema: GraphQLSchema
1516
gatsbyNodeTypes: IGatsbyNodeConfig[]
1617
gatsbyFieldAliases?: IGatsbyFieldAliases
17-
customFragments: Array<GraphQLSource | string>
18+
customFragments:
19+
| Array<GraphQLSource | string>
20+
| Map<RemoteTypeName, GraphQLSource | string>
1821
}
1922

2023
/**
@@ -28,9 +31,13 @@ export function compileNodeQueries({
2831
customFragments,
2932
}: ICompileNodeDocumentsArgs): Map<RemoteTypeName, DocumentNode> {
3033
const documents = new Map<RemoteTypeName, DocumentNode>()
31-
const fragments = customFragments
32-
.map(fragment => parse(fragment))
33-
.flatMap(doc => doc.definitions.filter(GraphQLAST.isFragment))
34+
const allFragmentDocs: DocumentNode[] = []
35+
customFragments.forEach(fragmentString => {
36+
allFragmentDocs.push(parse(fragmentString))
37+
})
38+
const fragments = flatMap(allFragmentDocs, doc =>
39+
doc.definitions.filter(GraphQLAST.isFragment)
40+
)
3441

3542
const nodeFragmentMap = compileNodeFragments({
3643
schema,

0 commit comments

Comments
 (0)
Please sign in to comment.