graphql.language.FieldDefinition Java Examples
The following examples show how to use
graphql.language.FieldDefinition.
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: GqlParentType.java From manifold with Apache License 2.0 | 6 votes |
private Type getType( Node def ) { if( def instanceof VariableDefinition ) { return ((VariableDefinition)def).getType(); } if( def instanceof InputValueDefinition ) { return ((InputValueDefinition)def).getType(); } if( def instanceof FieldDefinition ) { return ((FieldDefinition)def).getType(); } throw new IllegalStateException(); }
Example #2
Source File: GqlParentType.java From manifold with Apache License 2.0 | 6 votes |
private void addObjectExtensions( ObjectTypeDefinition type, SrcLinkedClass srcClass ) { List<FieldDefinition> baseFieldDefinitions = type.getFieldDefinitions(); List<ObjectTypeExtensionDefinition> objectExtensions = _registry.objectTypeExtensions().get( type.getName() ); if( objectExtensions != null ) { for( ObjectTypeExtensionDefinition ext: objectExtensions ) { List<FieldDefinition> extFieldDefinitions = ext.getFieldDefinitions(); for( FieldDefinition member: extFieldDefinitions ) { addMember( srcClass, member, name -> baseFieldDefinitions.stream().anyMatch( f -> f.getName().equals( name ) ) || extFieldDefinitions.stream().anyMatch( f -> f.getName().equals( name ) ) ); } } } }
Example #3
Source File: GqlParentType.java From manifold with Apache License 2.0 | 6 votes |
private void addInnerInterfaceType( InterfaceTypeDefinition type, SrcLinkedClass enclosingType ) { String identifier = makeIdentifier( type.getName(), false ); String fqn = getFqn() + '.' + identifier; SrcLinkedClass srcClass = new SrcLinkedClass( fqn, enclosingType, Interface ) .addInterface( IJsonBindingsBacked.class.getSimpleName() ) .addAnnotation( new SrcAnnotationExpression( Structural.class.getSimpleName() ) .addArgument( "factoryClass", Class.class, identifier + ".ProxyFactory.class" ) ) .modifiers( Modifier.PUBLIC ); addUnionInterfaces( type, srcClass ); addActualNameAnnotation( srcClass, type.getName(), false ); addSourcePositionAnnotation( srcClass, type, srcClass ); addProxyFactory( srcClass ); List<FieldDefinition> fieldDefinitions = type.getFieldDefinitions(); for( FieldDefinition member: fieldDefinitions ) { addMember( srcClass, member, name -> fieldDefinitions.stream().anyMatch( f -> f.getName().equals( name ) ) ); } addInterfaceExtensions( type, srcClass ); enclosingType.addInnerClass( srcClass ); }
Example #4
Source File: GqlParentType.java From manifold with Apache License 2.0 | 6 votes |
private void addInterfaceExtensions( InterfaceTypeDefinition type, SrcLinkedClass srcClass ) { List<FieldDefinition> baseFieldDefinitions = type.getFieldDefinitions(); List<InterfaceTypeExtensionDefinition> interfaceExtensions = _registry.interfaceTypeExtensions().get( type.getName() ); if( interfaceExtensions != null ) { for( InterfaceTypeExtensionDefinition ext: interfaceExtensions ) { List<FieldDefinition> extFieldDefinitions = ext.getFieldDefinitions(); for( FieldDefinition member: extFieldDefinitions ) { addMember( srcClass, member, name -> baseFieldDefinitions.stream().anyMatch( f -> f.getName().equals( name ) ) || extFieldDefinitions.stream().anyMatch( f -> f.getName().equals( name ) ) ); } } } }
Example #5
Source File: GraphQLIntrospectionResultToSchema.java From js-graphql-intellij-plugin with MIT License | 6 votes |
private List<FieldDefinition> createFields(List<Map<String, Object>> fields) { List<FieldDefinition> result = new ArrayList<>(); for (Map<String, Object> field : fields) { List<Map<String, Object>> args = (List<Map<String, Object>>) field.get("args"); List<InputValueDefinition> inputValueDefinitions = createInputValueDefinitions(args); FieldDefinition fieldDefinition = FieldDefinition.newFieldDefinition() .name((String) field.get("name")) .description(getDescription(field)) .type(createTypeIndirection((Map<String, Object>) field.get("type"))) .inputValueDefinitions(inputValueDefinitions) .directives(createDeprecatedDirective(field)) .build(); result.add(fieldDefinition); } return result; }
Example #6
Source File: GraphQLSchemaDefinition.java From carbon-apimgt with Apache License 2.0 | 6 votes |
/** * Extract GraphQL Types and Fields from given schema * * @param schema GraphQL Schema * @return list of all types and fields */ public List<GraphqlSchemaType> extractGraphQLTypeList(String schema) { List<GraphqlSchemaType> typeList = new ArrayList<>(); SchemaParser schemaParser = new SchemaParser(); TypeDefinitionRegistry typeRegistry = schemaParser.parse(schema); Map<java.lang.String, TypeDefinition> list = typeRegistry.types(); for (Map.Entry<String, TypeDefinition> entry : list.entrySet()) { if (entry.getValue() instanceof ObjectTypeDefinition) { GraphqlSchemaType graphqlSchemaType = new GraphqlSchemaType(); List<String> fieldList = new ArrayList<>(); graphqlSchemaType.setType(entry.getValue().getName()); for (FieldDefinition fieldDef : ((ObjectTypeDefinition) entry.getValue()).getFieldDefinitions()) { fieldList.add(fieldDef.getName()); } graphqlSchemaType.setFieldList(fieldList); typeList.add(graphqlSchemaType); } } return typeList; }
Example #7
Source File: Generator.java From smallrye-graphql with Apache License 2.0 | 5 votes |
private JavaType returnType() { ObjectTypeDefinition query = (ObjectTypeDefinition) schema.getType("Query") .orElseThrow(() -> new GraphQlGeneratorException("'Query' type not found in schema")); FieldDefinition fieldDefinition = query.getFieldDefinitions().stream() .filter(f -> f.getName().equals(method.getName())) .findAny() .orElseThrow(() -> new GraphQlGeneratorException("field (method) '" + method.getName() + "' not found in " + query.getFieldDefinitions().stream().map(FieldDefinition::getName).collect(listString()))); List<String> selections = operation.getSelectionSet().getSelectionsOfType(Field.class).stream() .flatMap(this::selectedFields) .map(Field::getName) .collect(toList()); return new JavaType(fieldDefinition.getType(), selections); }
Example #8
Source File: GqlParentType.java From manifold with Apache License 2.0 | 5 votes |
private void addInnerObjectType( ObjectTypeDefinition type, SrcLinkedClass enclosingType ) { String identifier = makeIdentifier( type.getName(), false ); String fqn = getFqn() + '.' + identifier; SrcLinkedClass srcClass = new SrcLinkedClass( fqn, enclosingType, Interface ) .addInterface( IJsonBindingsBacked.class.getSimpleName() ) .addAnnotation( new SrcAnnotationExpression( Structural.class.getSimpleName() ) .addArgument( "factoryClass", Class.class, identifier + ".ProxyFactory.class" ) ) .modifiers( Modifier.PUBLIC ); addUnionInterfaces( type, srcClass ); addActualNameAnnotation( srcClass, type.getName(), false ); addSourcePositionAnnotation( srcClass, type, srcClass ); List<Type> interfaces = type.getImplements(); addInterfaces( srcClass, interfaces ); addProxyFactory( srcClass ); addBuilder( srcClass, type ); addCreateMethod( srcClass, type ); addBuilderMethod( srcClass, type ); addLoadMethod( srcClass ); addCopier( srcClass, type ); addCopierMethod( srcClass ); addCopyMethod( srcClass ); List<FieldDefinition> fieldDefinitions = type.getFieldDefinitions(); for( FieldDefinition member: fieldDefinitions ) { addMember( srcClass, member, name -> fieldDefinitions.stream().anyMatch( f -> f.getName().equals( name ) ) ); } addObjectExtensions( type, srcClass ); enclosingType.addInnerClass( srcClass ); }
Example #9
Source File: GqlParentType.java From manifold with Apache License 2.0 | 5 votes |
private void addIntersectionMethods( SrcLinkedClass srcClass, UnionTypeDefinition union ) { Set<Pair<String, String>> fieldDefs = new HashSet<>(); Map<String, FieldDefinition> nameToFieldDef = new HashMap<>(); for( Type memberType: union.getMemberTypes() ) { TypeDefinition typeDef = findTypeDefinition( memberType ); if( typeDef instanceof ObjectTypeDefinition ) { if( fieldDefs.isEmpty() ) { fieldDefs.addAll( ((ObjectTypeDefinition)typeDef).getFieldDefinitions() .stream().map( e -> { nameToFieldDef.put( e.getName(), e ); return new Pair<>( e.getName(), e.getType().toString() ); } ).collect( Collectors.toSet() ) ); } else { fieldDefs.retainAll( ((ObjectTypeDefinition)typeDef).getFieldDefinitions() .stream().map( e -> new Pair<>( e.getName(), e.getType().toString() ) ).collect( Collectors.toSet() ) ); } } } fieldDefs.forEach( fieldDef -> addMember( srcClass, null, nameToFieldDef.get( fieldDef.getFirst() ).getType(), fieldDef.getFirst(), name -> fieldDefs.stream().anyMatch( f -> f.getFirst().equals( name ) ) ) ); }
Example #10
Source File: STModel.java From graphql-apigen with Apache License 2.0 | 5 votes |
private List<Field> getFields(ObjectTypeDefinition def) { List<Field> fields = new ArrayList<Field>(); for ( FieldDefinition fieldDef : def.getFieldDefinitions() ) { Field field = new Field(fieldDef.getName(), toJavaTypeName(fieldDef.getType())); field.graphQLType = toGraphQLType(fieldDef.getType()); field.dataResolver = toDataResolver(fieldDef.getType()); field.args = toArgs(fieldDef.getInputValueDefinitions()); fields.add(field); } return fields; }
Example #11
Source File: STModel.java From graphql-apigen with Apache License 2.0 | 5 votes |
private List<Field> getFields(InterfaceTypeDefinition def) { List<Field> fields = new ArrayList<Field>(); for ( FieldDefinition fieldDef : def.getFieldDefinitions() ) { Field field = new Field(fieldDef.getName(), toJavaTypeName(fieldDef.getType())); field.args = toArgs(fieldDef.getInputValueDefinitions()); fields.add(field); } return fields; }
Example #12
Source File: GraphQLSchemaDefinition.java From carbon-apimgt with Apache License 2.0 | 5 votes |
/** * * @param entry Entry * @param operationArray operationArray */ private void addOperations(Map.Entry<String, TypeDefinition> entry, List<URITemplate> operationArray) { for (FieldDefinition fieldDef : ((ObjectTypeDefinition) entry.getValue()).getFieldDefinitions()) { URITemplate operation = new URITemplate(); operation.setHTTPVerb(entry.getKey()); operation.setUriTemplate(fieldDef.getName()); operationArray.add(operation); } }
Example #13
Source File: Generator.java From smallrye-graphql with Apache License 2.0 | 4 votes |
private String toJava(FieldDefinition field) { return new JavaType(field.getType(), fieldNames) + " " + field.getName(); }
Example #14
Source File: GqlParentType.java From manifold with Apache License 2.0 | 4 votes |
private void addMember( SrcLinkedClass srcClass, FieldDefinition member, Predicate<String> duplicateChecker ) { Type type = member.getType(); String name = makeIdentifier( member.getName(), false ); addMember( srcClass, member, type, name, duplicateChecker ); }
Example #15
Source File: STModel.java From graphql-apigen with Apache License 2.0 | 4 votes |
private void addImports(Collection<String> imports, ObjectTypeDefinition def) { for ( FieldDefinition fieldDef : def.getFieldDefinitions() ) { addImports(imports, fieldDef.getType()); } }
Example #16
Source File: STModel.java From graphql-apigen with Apache License 2.0 | 4 votes |
private void addImports(Collection<String> imports, InterfaceTypeDefinition def) { for ( FieldDefinition fieldDef : def.getFieldDefinitions() ) { addImports(imports, fieldDef.getType()); } }