graphql.language.EnumValueDefinition Java Examples

The following examples show how to use graphql.language.EnumValueDefinition. 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 vote down vote up
private void addInnerEnumType( EnumTypeDefinition type, SrcLinkedClass enclosingType )
{
  String identifier = makeIdentifier( type.getName(), false );
  SrcLinkedClass srcClass = new SrcLinkedClass( getFqn() + '.' + identifier, enclosingType, Enum )
    .modifiers( Modifier.PUBLIC )
    .addInterface( IBindingType.class.getSimpleName() );
  addActualNameAnnotation( srcClass, type.getName(), false );
  addSourcePositionAnnotation( srcClass, type, srcClass );
  for( EnumValueDefinition member: type.getEnumValueDefinitions() )
  {
    addEnumConstant( identifier, srcClass, member );
  }
  addEnumExtensions( type, srcClass );
  srcClass.addMethod(
    new SrcMethod( srcClass )
      .name( "toBindingValue" )
      .modifiers( Modifier.PUBLIC )
      .returns( Object.class )
      .body( "return name();" ) );
  enclosingType.addInnerClass( srcClass );
}
 
Example #2
Source File: GraphQLIntrospectionResultToSchema.java    From js-graphql-intellij-plugin with MIT License 6 votes vote down vote up
@SuppressWarnings("unchecked")
EnumTypeDefinition createEnum(Map<String, Object> input) {
    assertTrue(input.get("kind").equals("ENUM"), () -> "wrong input");

    final List<Map<String, Object>> enumValues = (List<Map<String, Object>>) input.get("enumValues");
    final List<EnumValueDefinition> enumValueDefinitions = Lists.newArrayList();
    for (Map<String, Object> enumValue : enumValues) {

        EnumValueDefinition enumValueDefinition = EnumValueDefinition.newEnumValueDefinition()
                .name((String) enumValue.get("name"))
                .description(getDescription(enumValue))
                .directives(createDeprecatedDirective(enumValue))
                .build();

        enumValueDefinitions.add(enumValueDefinition);
    }

    return EnumTypeDefinition.newEnumTypeDefinition()
            .name((String) input.get("name"))
            .description(getDescription(input))
            .enumValueDefinitions(enumValueDefinitions)
            .build();
}
 
Example #3
Source File: GqlParentType.java    From manifold with Apache License 2.0 5 votes vote down vote up
private void addEnumExtensions( EnumTypeDefinition type, SrcLinkedClass srcClass )
{
  List<EnumTypeExtensionDefinition> enumExtensions = _registry.enumTypeExtensions().get( type.getName() );
  if( enumExtensions != null )
  {
    String declaringType = makeIdentifier( type.getName(), false );
    for( EnumTypeExtensionDefinition ext: enumExtensions )
    {
      for( EnumValueDefinition member: ext.getEnumValueDefinitions() )
      {
        addEnumConstant( declaringType, srcClass, member );
      }
    }
  }
}
 
Example #4
Source File: STModel.java    From graphql-apigen with Apache License 2.0 5 votes vote down vote up
private List<Field> getFields(EnumTypeDefinition def) {
    List<Field> fields = new ArrayList<Field>();
    for ( EnumValueDefinition fieldDef : def.getEnumValueDefinitions() ) {
        fields.add(new Field(fieldDef.getName(), null));
    }
    return fields;
}
 
Example #5
Source File: GqlParentType.java    From manifold with Apache License 2.0 4 votes vote down vote up
private void addEnumConstant( String identifier, SrcLinkedClass srcClass, EnumValueDefinition member )
{
  SrcField enumConst = new SrcField( makeIdentifier( member.getName(), false ), identifier );
  addSourcePositionAnnotation( srcClass, member, enumConst );
  srcClass.addEnumConst( enumConst );
}