This repository has been archived by the owner on Apr 15, 2020. It is now read-only.
forked from ardatan/graphql-tools
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
healSchema cannot automatically include reparsing of default values. Automatic reparsing assumes that the default value corresponds to the old type, but that may not always be the case, and when it is not the case, the default value will be lost if automatic reparsing is implemented as in 6.3.6.
- Loading branch information
Showing
3 changed files
with
39 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { getNamedType, GraphQLInputObjectType, GraphQLSchema, GraphQLObjectType } from 'graphql'; | ||
import { IDefaultValueIteratorFn } from '../Interfaces'; | ||
|
||
function forEachDefaultValue(schema: GraphQLSchema, fn: IDefaultValueIteratorFn): void { | ||
|
||
const typeMap = schema.getTypeMap(); | ||
Object.keys(typeMap).forEach(typeName => { | ||
const type = typeMap[typeName]; | ||
|
||
if (!getNamedType(type).name.startsWith('__')) { | ||
if (type instanceof GraphQLObjectType) { | ||
const fields = type.getFields(); | ||
Object.keys(fields).forEach(fieldName => { | ||
const field = fields[fieldName]; | ||
|
||
field.args.forEach(arg => { | ||
arg.defaultValue = fn(arg.type, arg.defaultValue); | ||
}); | ||
}); | ||
} else if (type instanceof GraphQLInputObjectType) { | ||
const fields = type.getFields(); | ||
Object.keys(fields).forEach(fieldName => { | ||
const field = fields[fieldName]; | ||
field.defaultValue = fn(field.type, field.defaultValue); | ||
}); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
export default forEachDefaultValue; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters