本文整理汇总了Java中graphql.schema.GraphQLObjectType.Builder方法的典型用法代码示例。如果您正苦于以下问题:Java GraphQLObjectType.Builder方法的具体用法?Java GraphQLObjectType.Builder怎么用?Java GraphQLObjectType.Builder使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类graphql.schema.GraphQLObjectType
的用法示例。
在下文中一共展示了GraphQLObjectType.Builder方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: postConstruct
import graphql.schema.GraphQLObjectType; //导入方法依赖的package包/类
@PostConstruct
public void postConstruct() {
GraphQLObjectType.Builder queryBuilder = newObject().name(properties.getRootQueryName());
GraphQLObjectType.Builder mutationBuilder = newObject().name(properties.getRootMutationName());
if (StringUtils.hasText(properties.getRootQueryDescription())) {
queryBuilder = queryBuilder.description(properties.getRootQueryDescription());
}
if (StringUtils.hasText(properties.getRootMutationDescription())) {
mutationBuilder = mutationBuilder.description(properties.getRootMutationDescription());
}
buildSchemaFromDefinitions(queryBuilder, mutationBuilder);
}
示例2: buildSchemaFromDefinitions
import graphql.schema.GraphQLObjectType; //导入方法依赖的package包/类
private void buildSchemaFromDefinitions(GraphQLObjectType.Builder queryBuilder, GraphQLObjectType.Builder mutationBuilder) {
boolean foundQueryDefinitions = false;
boolean foundMutationDefinitions = false;
for(val graphQlFieldsDefinition : graphQlFieldsDefinitions){
val queryFields = graphQlFieldsDefinition.getQueryFields();
if (queryFields != null && queryFields.size() > 0) {
queryBuilder = queryBuilder.fields(queryFields);
foundQueryDefinitions = true;
}
val mutationFields = graphQlFieldsDefinition.getMutationFields();
if (mutationFields != null && mutationFields.size() > 0) {
mutationBuilder = mutationBuilder.fields(mutationFields);
foundMutationDefinitions = true;
}
}
buildSchema(queryBuilder, mutationBuilder, foundQueryDefinitions, foundMutationDefinitions);
}
示例3: buildSchema
import graphql.schema.GraphQLObjectType; //导入方法依赖的package包/类
private void buildSchema(GraphQLObjectType.Builder queryBuilder, GraphQLObjectType.Builder mutationBuilder, boolean foundQueryDefinitions, boolean foundMutationDefinitions) {
log.debug("Start building graphql schema");
GraphQLSchema.Builder schemaBuilder = GraphQLSchema.newSchema();
if (foundQueryDefinitions) {
schemaBuilder = schemaBuilder.query(queryBuilder.build());
}
if (foundMutationDefinitions) {
schemaBuilder = schemaBuilder.mutation(mutationBuilder.build());
}
if (foundQueryDefinitions || foundMutationDefinitions) {
schema = schemaBuilder.build();
} else {
schema = generateGettingStartedGraphQlSchema();
}
}
示例4: generateOutputType
import graphql.schema.GraphQLObjectType; //导入方法依赖的package包/类
protected GraphQLOutputType generateOutputType(Object object) {
//An enum is a special case in both java and graphql,
//and must be checked for while generating other kinds of types
GraphQLEnumType enumType = generateEnumType(object);
if (enumType != null) {
return enumType;
}
List<GraphQLFieldDefinition> fields = getOutputFieldDefinitions(object);
if (fields == null || fields.isEmpty()) {
return null;
}
String typeName = getGraphQLTypeNameOrIdentityCode(object);
GraphQLObjectType.Builder builder = newObject()
.name(typeName)
.fields(fields)
.description(getTypeDescription(object));
GraphQLInterfaceType[] interfaces = getInterfaces(object);
if (interfaces != null) {
builder.withInterfaces(interfaces);
}
return builder.build();
}
示例5: toGraphQLType
import graphql.schema.GraphQLObjectType; //导入方法依赖的package包/类
@Override
public GraphQLObjectType toGraphQLType(String typeName, AnnotatedType javaType, Set<Type> abstractTypes, OperationMapper operationMapper, BuildContext buildContext) {
GraphQLObjectType.Builder typeBuilder = newObject()
.name(typeName)
.description(buildContext.typeInfoGenerator.generateTypeDescription(javaType));
GraphQLType graphQLType = javaType.getAnnotation(GraphQLType.class);
List<String> fieldOrder = graphQLType != null ? Arrays.asList(graphQLType.fieldOrder()) : Collections.emptyList();
List<GraphQLFieldDefinition> fields = getFields(javaType, fieldOrder, buildContext, operationMapper);
fields.forEach(typeBuilder::field);
List<GraphQLOutputType> interfaces = getInterfaces(javaType, abstractTypes, fields, buildContext, operationMapper);
interfaces.forEach(inter -> {
if (inter instanceof GraphQLInterfaceType) {
typeBuilder.withInterface((GraphQLInterfaceType) inter);
} else {
typeBuilder.withInterface((GraphQLTypeReference) inter);
}
});
GraphQLObjectType type = new MappedGraphQLObjectType(typeBuilder.build(), javaType);
interfaces.forEach(inter -> buildContext.typeRepository.registerCovariantType(inter.getName(), javaType, type));
buildContext.typeRepository.registerObjectType(type);
return type;
}
示例6: objectType
import graphql.schema.GraphQLObjectType; //导入方法依赖的package包/类
private GraphQLObjectType objectType(Class<?> record,
List<PropertyDescriptor> fields,
PhantasmProcessor processor) {
Map<String, Class<?>> references = TABLES.get(record)
.getReferences()
.stream()
.collect(Collectors.toMap(fk -> camel(fk.getFields()
.get(0)
.getName()),
fk -> fk.getTable()
.getRecordType()));
GraphQLObjectType.Builder builder = new GraphQLObjectType.Builder();
builder.name(translated(record));
fields.forEach(field -> {
builder.field(f -> references.containsKey(field.getName()) ? buildReference(f,
field,
processor,
references.get(field.getName()))
: buildPrimitive(f,
field,
processor));
});
return builder.build();
}
示例7: addPhantasmCast
import graphql.schema.GraphQLObjectType; //导入方法依赖的package包/类
private void addPhantasmCast(GraphQLObjectType.Builder typeBuilder,
Entry<FacetRecord, FacetFields> resolved) {
typeBuilder.field(GraphQLFieldDefinition.newFieldDefinition()
.name(String.format("as%s",
WorkspacePresentation.toTypeName(resolved.getKey()
.getName())))
.description(String.format("Cast to the %s facet",
resolved.getKey()
.getName()))
.type(new GraphQLTypeReference(resolved.getValue()
.getName()))
.dataFetcher(env -> {
Existential existential = (Existential) env.getSource();
PhantasmCRUD crud = FacetFields.ctx(env);
crud.cast(existential.getRecord(),
new Aspect(crud.getModel()
.create(),
resolved.getKey()));
return existential;
})
.build());
}
示例8: buildTypeFromBean
import graphql.schema.GraphQLObjectType; //导入方法依赖的package包/类
/**
* Constructs the GraphQL Type from a bean (ie Report, Person, Position...)
* Scans all 'getter' methods, and those annotated with @GraphQLFetcher
*/
private GraphQLObjectType buildTypeFromBean(String name, Class<? extends IGraphQLBean> beanClazz) {
GraphQLObjectType.Builder builder = GraphQLObjectType.newObject()
.name(name);
//Find all of the methods to use as Fields. Either getters, or @GraphQLFetcher annotated
//Get a set of all unique names.
Map<String,Type> methodReturnTypes = new HashMap<String,Type>();
for (Method m : beanClazz.getMethods()) {
String methodName = null;
if (m.isAnnotationPresent(GraphQLIgnore.class)) { continue; }
if (m.getName().startsWith("get")) {
if (m.getName().equalsIgnoreCase("getClass")) { continue; }
methodName = GraphQLUtils.lowerCaseFirstLetter(m.getName().substring(3));
} else if (m.getName().startsWith("is")) {
methodName = GraphQLUtils.lowerCaseFirstLetter(m.getName().substring(2));
} else if (m.isAnnotationPresent(GraphQLFetcher.class)) {
methodName = m.getAnnotation(GraphQLFetcher.class).value();
}
if (methodName != null) {
methodReturnTypes.put(methodName, m.getGenericReturnType());
}
}
for (Map.Entry<String, Type> entry : methodReturnTypes.entrySet()) {
String fieldName = entry.getKey();
Type retType = entry.getValue();
try {
builder.field(GraphQLUtils.buildFieldWithArgs(fieldName, retType, beanClazz));
} catch (Exception e) {
throw new RuntimeException(String.format("Unable to build GraphQL field %s on bean %s, error was %s",
fieldName, beanClazz.getName(), e.getMessage()), e);
}
}
return builder.build();
}
示例9: rebuildSchema
import graphql.schema.GraphQLObjectType; //导入方法依赖的package包/类
private void rebuildSchema()
{
GraphQLSchema.Builder schemaBuilder = GraphQLSchema.newSchema();
GraphQLObjectType.Builder rootQuery = newObject().name( "queryRoot" );
for ( Map.Entry<String,String> field : fields.entrySet() )
{
rootQuery.field( newFieldDefinition()
.type(GraphQLString)
.name(field.getKey())
.dataFetcher( (env) ->
{
GraphDatabaseService db =
(GraphDatabaseService) ((Map<String, Object>)env.getContext()).get( "db" );
Result result = db.execute( field.getValue() );
if(result.hasNext())
{
return result.next().values().iterator().next().toString();
}
else
{
return "N/A";
}
})
.build());
}
schema = schemaBuilder
.query(rootQuery.build())
.build();
}
示例10: createType
import graphql.schema.GraphQLObjectType; //导入方法依赖的package包/类
public GraphQLObjectType createType() {
GraphQLObjectType.Builder root = newObject();
root.name(PROJECT_REFERENCE_TYPE_NAME);
interfaceTypeProvider.addCommonFields(root);
// .name
root.field(newFieldDefinition().name("name").description("The name of the project").type(GraphQLString));
return root.build();
}
示例11: contributeTo
import graphql.schema.GraphQLObjectType; //导入方法依赖的package包/类
public void contributeTo(GraphQLObjectType.Builder query,
GraphQLObjectType.Builder mutation,
PhantasmProcessor processor) {
manifested.stream()
.map(table -> table.getRecordType())
.forEach(record -> contributeTo(query, record, mutation,
processor));
}
示例12: buildMeta
import graphql.schema.GraphQLObjectType; //导入方法依赖的package包/类
public GraphQLSchema buildMeta() throws Exception {
PhantasmProcessor processor = new PhantasmProcessor();
registerBaseTypes(Collections.emptyMap(), processor);
GraphQLObjectType.Builder query = processor.getObjectBuilder(MetaQueries.class);
GraphQLObjectType.Builder mutation = processor.getObjectBuilder(MetaMutations.class);
JooqSchema jooqSchema = JooqSchema.meta(processor);
jooqSchema.contributeTo(query, mutation, processor);
return GraphQLSchema.newSchema()
.query(query.build())
.mutation(mutation.build())
.build(jooqSchema.getTypes());
}
示例13: toBuilder
import graphql.schema.GraphQLObjectType; //导入方法依赖的package包/类
GraphQLObjectType.Builder toBuilder(GraphQLObjectType input) {
return newObject()
.name(input.getName())
.description(input.getDescription())
.fields(input.getFieldDefinitions());
}
示例14: get
import graphql.schema.GraphQLObjectType; //导入方法依赖的package包/类
@Override
public GraphQLSchema get() {
Map<String, ? extends Function<String, Object>> nodeDataFetchers =
this.nodeDataFetchers
.stream()
.collect(Collectors.toMap(e -> e.getClassName(), Function.identity()));
GraphQLObjectType.Builder queryType =
newObject().name("QueryType").fields(Lists.newArrayList(queryFields));
ProtoRegistry protoRegistry =
ProtoRegistry.newBuilder().addAll(fileDescriptors).add(modifications).build();
if (protoRegistry.hasRelayNode()) {
queryType.field(
new Relay()
.nodeField(
protoRegistry.getRelayNode(),
environment -> {
String id = environment.getArgument("id");
Relay.ResolvedGlobalId resolvedGlobalId = new Relay().fromGlobalId(id);
Function<String, ?> stringFunction =
nodeDataFetchers.get(resolvedGlobalId.getType());
if (stringFunction == null) {
throw new RuntimeException(
String.format(
"Relay Node fetcher not implemented for type=%s",
resolvedGlobalId.getType()));
}
return stringFunction.apply(resolvedGlobalId.getId());
}));
}
if (mutationFields.isEmpty()) {
return GraphQLSchema.newSchema().query(queryType).build(protoRegistry.listTypes());
}
GraphQLObjectType mutationType =
newObject().name("MutationType").fields(Lists.newArrayList(mutationFields)).build();
return GraphQLSchema.newSchema()
.query(queryType)
.mutation(mutationType)
.build(protoRegistry.listTypes());
}
示例15: classToQueryObject
import graphql.schema.GraphQLObjectType; //导入方法依赖的package包/类
/**
* Converts a non Elide object into a GraphQL Query object. Any attribute which cannot be converted is skipped.
* @param clazz The non Elide object class
* @param fetcher The data fetcher to assign the newly created GraphQL object
* @return A newly created GraphQL object.
*/
public GraphQLObjectType classToQueryObject(
Class<?> clazz,
DataFetcher fetcher) {
log.info("Building query object for type: {}", clazz.getName());
if (!nonEntityDictionary.hasBinding(clazz)) {
nonEntityDictionary.bindEntity(clazz);
}
/* Check if we've already converted this */
if (outputConversions.containsKey(clazz)) {
return outputConversions.get(clazz);
}
GraphQLObjectType.Builder objectBuilder = newObject();
objectBuilder.name(toValidNameName(clazz.getName()));
for (String attribute : nonEntityDictionary.getAttributes(clazz)) {
Class<?> attributeClass = nonEntityDictionary.getType(clazz, attribute);
GraphQLFieldDefinition.Builder fieldBuilder = newFieldDefinition()
.name(attribute)
.dataFetcher(fetcher);
GraphQLOutputType attributeType =
attributeToQueryObject(clazz,
attributeClass, attribute, fetcher, nonEntityDictionary);
if (attributeType == null) {
continue;
}
fieldBuilder.type(attributeType);
objectBuilder.field(fieldBuilder);
}
GraphQLObjectType object = objectBuilder.build();
outputConversions.put(clazz, object);
return object;
}