本文整理汇总了TypeScript中graphql.GraphQLSchema.getType方法的典型用法代码示例。如果您正苦于以下问题:TypeScript GraphQLSchema.getType方法的具体用法?TypeScript GraphQLSchema.getType怎么用?TypeScript GraphQLSchema.getType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类graphql.GraphQLSchema
的用法示例。
在下文中一共展示了GraphQLSchema.getType方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1:
Object.keys(fragments).forEach(fragmentName => {
const fragment = fragments[fragmentName];
const typeName = fragment.typeCondition.name.value;
const innerType = schema.getType(typeName);
if (innerType) {
validFragments.push(fragment);
}
});
示例2: it
it('should parse descriptions on new fields', () => {
const Query = mergedSchema.getQueryType();
expect(Query.getFields().linkTest.description).to.equal(
'A new field on the root query.',
);
const Booking = mergedSchema.getType('Booking') as GraphQLObjectType;
expect(Booking.getFields().property.description).to.equal(
'The property of the booking.',
);
const Property = mergedSchema.getType('Property') as GraphQLObjectType;
const bookingsField = Property.getFields().bookings;
expect(bookingsField.description).to.equal('A list of bookings.');
expect(bookingsField.args[0].description).to.equal(
'The maximum number of bookings to retrieve.',
);
});
示例3: handleEnum
const handleNamedTypeInput: (type: TypeNode, isNonNull: boolean) => string | undefined = (type, isNonNull) => {
if (type.kind === 'NamedType' && type.name.kind === 'Name' && type.name.value) {
const newType: GraphQLType = parsedSchema.getType(type.name.value);
if (newType instanceof GraphQLEnumType) {
return handleEnum(newType, isNonNull);
} else if (newType instanceof GraphQLInputObjectType) {
return handleInputObject(newType, isNonNull);
}
}
};
示例4: collectFragmentVariables
function collectFragmentVariables(
targetSchema: GraphQLSchema,
fragmentSet: Object,
validFragments: Array<FragmentDefinitionNode>,
validFragmentsWithType: { [name: string]: GraphQLType },
usedFragments: Array<string>,
) {
let usedVariables: Array<string> = [];
let newFragments: Array<FragmentDefinitionNode> = [];
while (usedFragments.length !== 0) {
const nextFragmentName = usedFragments.pop();
const fragment = validFragments.find(
fr => fr.name.value === nextFragmentName,
);
if (fragment) {
const name = nextFragmentName;
const typeName = fragment.typeCondition.name.value;
const type = targetSchema.getType(typeName);
const {
selectionSet,
usedFragments: fragmentUsedFragments,
usedVariables: fragmentUsedVariables,
} = filterSelectionSet(
targetSchema,
type,
validFragmentsWithType,
fragment.selectionSet,
);
usedFragments = union(usedFragments, fragmentUsedFragments);
usedVariables = union(usedVariables, fragmentUsedVariables);
if (!fragmentSet[name]) {
fragmentSet[name] = true;
newFragments.push({
kind: Kind.FRAGMENT_DEFINITION,
name: {
kind: Kind.NAME,
value: name,
},
typeCondition: fragment.typeCondition,
selectionSet,
});
}
}
}
return {
usedVariables,
newFragments,
fragmentSet,
};
}
示例5:
Object.keys(typeMap).forEach(typeName => {
const type = typeMap[typeName];
if (isAbstractType(type)) {
const targetType = targetSchema.getType(typeName);
if (!isAbstractType(targetType)) {
const implementations = transformedSchema.getPossibleTypes(type) || [];
mapping[typeName] = implementations
.filter(impl => targetSchema.getType(impl.name))
.map(impl => impl.name);
}
}
});
示例6: implementsAbstractType
replacements.forEach(replacement => {
const typeName = replacement.typeName;
if (
implementsAbstractType(
targetSchema,
parentType,
targetSchema.getType(typeName),
)
) {
newSelections.push({
kind: Kind.FRAGMENT_SPREAD,
name: {
kind: Kind.NAME,
value: replacement.fragmentName,
},
});
}
});
示例7:
typeNames.forEach(typeName => {
const typeResolvers = resolvers[typeName];
const type = schema.getType(typeName);
if (type instanceof GraphQLObjectType) {
const interfaceResolvers = type
.getInterfaces()
.map(iFace => resolvers[iFace.name]);
extendedResolvers[typeName] = Object.assign(
{},
...interfaceResolvers,
typeResolvers,
);
} else {
if (typeResolvers) {
extendedResolvers[typeName] = typeResolvers;
}
}
});
示例8: GraphQLList
function healType<T extends GraphQLType>(type: T): T {
// Unwrap the two known wrapper types
if (type instanceof GraphQLList) {
type = new GraphQLList(healType(type.ofType)) as T;
} else if (type instanceof GraphQLNonNull) {
type = new GraphQLNonNull(healType(type.ofType)) as T;
} else if (isNamedType(type)) {
// If a type annotation on a field or an argument or a union member is
// any `GraphQLNamedType` with a `name`, then it must end up identical
// to `schema.getType(name)`, since `schema.getTypeMap()` is the source
// of truth for all named schema types.
const namedType = type as GraphQLNamedType;
const officialType = schema.getType(namedType.name);
if (officialType && namedType !== officialType) {
return officialType as T;
}
}
return type;
}
示例9: generateQueryName
return parsedSelection.definitions.map(def => {
if (def.kind === 'OperationDefinition') {
const ifaceName: string = generateQueryName(def);
const variableInterface: string = variablesToInterface(ifaceName, def.variableDefinitions);
const ret: IChildSelection[] = def.selectionSet.selections.map(sel => getChildSelections(def.operation, sel));
const fields: string[] = ret.map(x => x.iface);
const iface: string = postProcessor(exportFunction(interfaceBuilder(ifaceName, generateInterfaceDeclaration(fields))));
const additionalTypes: string[] = buildAdditionalTypes(ret);
return joinOutputs({
variables: variableInterface,
interface: iface,
additionalTypes,
});
} else if (def.kind === 'FragmentDefinition') {
const ifaceName: string = generateFragmentName(def.name.value);
// get the correct type
const onType: string = def.typeCondition.name.value;
const foundType: GraphQLType = parsedSchema.getType(onType);
const ret: IChildSelection[] = def.selectionSet.selections.map(sel => getChildSelections('query', sel, foundType));
const extensions: string[] = ret.filter(x => x.isFragment).map(x => x.iface);
const fields: string[] = ret.filter(x => !x.isFragment).map(x => x.iface);
const iface: string = postProcessor(
exportFunction(
interfaceBuilder(
addExtensionsToInterfaceName(ifaceName, extensions),
generateInterfaceDeclaration(fields)
)
)
);
const additionalTypes: string[] = buildAdditionalTypes(ret);
return joinOutputs({
interface: iface,
variables: '',
additionalTypes,
});
} else {
throw new Error(`Unsupported Definition ${def.kind}`);
}
}).concat(