-
-
Notifications
You must be signed in to change notification settings - Fork 824
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
export toConfig functions not available in graphql-js (#1433)
* export toConfig functions not available in graphql-js * avoid type,toConfig() workaround now that fieldToFieldConfig available additional benefit of fieldToFieldConfig is that rootFieldTransformer and fieldTransform argumenst in TransformRootFields and TransformObjectFields expect functions that convert fields to fieldConfig, so now end users can easily create their own functions
- Loading branch information
Showing
5 changed files
with
77 additions
and
21 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
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,51 @@ | ||
import { | ||
GraphQLArgument, | ||
GraphQLFieldConfigArgumentMap, | ||
GraphQLField, | ||
GraphQLInputField, | ||
GraphQLInputFieldConfig, | ||
GraphQLArgumentConfig, | ||
GraphQLFieldConfig, | ||
} from 'graphql'; | ||
|
||
export function inputFieldToFieldConfig(field: GraphQLInputField): GraphQLInputFieldConfig { | ||
return { | ||
description: field.description, | ||
type: field.type, | ||
defaultValue: field.defaultValue, | ||
extensions: field.extensions, | ||
astNode: field.astNode, | ||
}; | ||
} | ||
|
||
export function fieldToFieldConfig(field: GraphQLField<any, any>): GraphQLFieldConfig<any, any> { | ||
return { | ||
description: field.description, | ||
type: field.type, | ||
args: argsToFieldConfigArgumentMap(field.args), | ||
resolve: field.resolve, | ||
subscribe: field.subscribe, | ||
deprecationReason: field.deprecationReason, | ||
extensions: field.extensions, | ||
astNode: field.astNode, | ||
}; | ||
} | ||
|
||
export function argsToFieldConfigArgumentMap(args: ReadonlyArray<GraphQLArgument>): GraphQLFieldConfigArgumentMap { | ||
const newArguments = {}; | ||
args.forEach(arg => { | ||
newArguments[arg.name] = argumentToArgumentConfig(arg); | ||
}); | ||
|
||
return newArguments; | ||
} | ||
|
||
export function argumentToArgumentConfig(arg: GraphQLArgument): GraphQLArgumentConfig { | ||
return { | ||
description: arg.description, | ||
type: arg.type, | ||
defaultValue: arg.defaultValue, | ||
extensions: arg.extensions, | ||
astNode: arg.astNode, | ||
}; | ||
} |
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