graphql APIs
- GraphQLSchema
- DocumentNode
- GraphQLScalarType
- GraphQLObjectType
- GraphQLError
- buildSchema
- GraphQLResolveInfo
- parse
- GraphQLNonNull
- Kind
- GraphQLString
- GraphQLNamedType
- OperationDefinitionNode
- GraphQLEnumType
- GraphQLList
- GraphQLInputObjectType
- GraphQLInt
- GraphQLFloat
- GraphQLUnionType
- graphql
- GraphQLInterfaceType
- GraphQLField
- GraphQLBoolean
- getIntrospectionQuery
- FieldNode
- SelectionNode
- GraphQLOutputType
- printSchema
- GraphQLType
- SelectionSetNode
- Source
- buildClientSchema
- execute
- DefinitionNode
- FieldDefinitionNode
- isNonNullType
- validate
- isObjectType
- OperationTypeNode
- buildASTSchema
- GraphQLArgument
- visit
- ASTNode
- TypeNode
- NameNode
- NamedTypeNode
- isListType
- DirectiveNode
- StringValueNode
- isScalarType
- isInterfaceType
- ValueNode
- ExecutionResult
- GraphQLInputType
- TypeInfo
- visitWithTypeInfo
- ObjectTypeDefinitionNode
- ArgumentNode
- VariableDefinitionNode
- NonNullTypeNode
- Location
- FragmentDefinitionNode
- extendSchema
- specifiedDirectives
- getOperationAST
- validateSchema
- getNamedType
- GraphQLID
- isUnionType
- isInputObjectType
- GraphQLInputField
- subscribe
- ASTVisitor
- TypeDefinitionNode
- InterfaceTypeDefinitionNode
- VariableNode
- EnumTypeDefinitionNode
- InputValueDefinitionNode
- InlineFragmentNode
- ListTypeNode
- ValidationRule
- introspectionFromSchema
- defaultFieldResolver
- GraphQLFieldResolver
- IntrospectionField
- lexicographicSortSchema
- concatAST
- IntrospectionQuery
- isAbstractType
- GraphQLFieldConfigMap
- GraphQLFieldConfig
- GraphQLSchemaConfig
- GraphQLObjectTypeConfig
- printType
- isSpecifiedScalarType
- isEnumType
- GraphQLEnumValue
- specifiedRules
- GraphQLFieldMap
- GraphQLFormattedError
- ExecutableDefinitionNode
- ObjectTypeExtensionNode
- InterfaceTypeExtensionNode
- DirectiveDefinitionNode
- EnumTypeExtensionNode
- InputObjectTypeDefinitionNode
- InputObjectTypeExtensionNode
- TokenKind
- Token
- Lexer
- EnumValueNode
- ListValueNode
- BooleanValueNode
- BREAK
- GraphQLEnumTypeConfig
- GraphQLInputFieldConfigMap
- GraphQLFieldConfigArgumentMap
- GraphQLInterfaceTypeConfig
- GraphQLInputObjectTypeConfig
- GraphQLEnumValueConfigMap
- GraphQLTypeResolver
- isLeafType
- valueFromASTUntyped
- typeFromAST
- isCompositeType
- GraphQLCompositeType
- isType
- isEqualType
- SchemaMetaFieldDef
- TypeMetaFieldDef
- TypeNameMetaFieldDef
- NoUnusedFragmentsRule
- ValidationContext
- parseValue
- ExecutionArgs
- FormattedExecutionResult
- GraphQLEnumValueConfig
- TypeKind
- IntrospectionInputObjectType
- IntrospectionInputTypeRef
- IntrospectionInputValue
- IntrospectionListTypeRef
- IntrospectionNamedTypeRef
- IntrospectionNonNullTypeRef
- IntrospectionTypeRef
- IntrospectionType
- IntrospectionObjectType
- isNamedType
- assertValidSchema
Other Related APIs
graphql#GraphQLTypeResolver TypeScript Examples
The following examples show how to use
graphql#GraphQLTypeResolver.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: getTypeResolverFromOutputTCs.ts From graphql-mesh with MIT License | 5 votes |
export function getTypeResolverFromOutputTCs(
ajv: Ajv,
outputTypeComposers: (ObjectTypeComposer | UnionTypeComposer)[],
statusCodeOneOfIndexMap?: Record<string, number>
): GraphQLTypeResolver<any, any> {
const statusCodeTypeMap = new Map<string, ObjectTypeComposer | UnionTypeComposer>();
for (const statusCode in statusCodeOneOfIndexMap) {
statusCodeTypeMap.set(statusCode.toString(), outputTypeComposers[statusCodeOneOfIndexMap[statusCode]]);
}
return function resolveType(data: any, context: any, info: GraphQLResolveInfo) {
if (data.__typename) {
return data.__typename;
} else if (data.resourceType) {
return data.resourceType;
}
if (data.$response && statusCodeOneOfIndexMap) {
const responseData: ResponseData = data.$response;
const type = statusCodeTypeMap.get(responseData.status.toString()) || statusCodeTypeMap.get('default');
if (type) {
if ('getFields' in type) {
return type.getTypeName();
} else {
return type.getResolveType()(data, context, info, type.getType());
}
}
}
const validationErrors: Record<string, ErrorObject[]> = {};
for (const outputTypeComposer of outputTypeComposers) {
const validateFn = outputTypeComposer.getExtension('validateWithJSONSchema') as ValidateFunction;
if (validateFn) {
const isValid = validateFn(data);
const typeName = outputTypeComposer.getTypeName();
if (isValid) {
if ('getFields' in outputTypeComposer) {
return outputTypeComposer.getTypeName();
} else {
return outputTypeComposer.getResolveType()(data, context, info, outputTypeComposer.getType());
}
}
validationErrors[typeName] = ajv.errors || validateFn.errors;
}
}
if (data.$response) {
const responseData: ResponseData = data.$response;
const error = new GraphQLError(
`HTTP Error: ${responseData.status}`,
undefined,
undefined,
undefined,
undefined,
undefined,
{
...responseData,
responseJson: data,
}
);
console.error(error);
return error;
}
const error = new GraphQLError(`Received data doesn't met the union`, null, null, null, null, null, {
validationErrors,
});
console.error(error);
return error;
};
}