graphql.language.EnumTypeDefinition Java Examples

The following examples show how to use graphql.language.EnumTypeDefinition. 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: TypeEntry.java    From graphql-apigen with Apache License 2.0 6 votes vote down vote up
private static List<Directive> getDirectives(Definition def) {
    if ( def instanceof ObjectTypeDefinition ) {
        return ((ObjectTypeDefinition)def).getDirectives();
    } if ( def instanceof InterfaceTypeDefinition ) {
        return ((InterfaceTypeDefinition)def).getDirectives();
    } if ( def instanceof EnumTypeDefinition ) {
        return ((EnumTypeDefinition)def).getDirectives();
    } if ( def instanceof ScalarTypeDefinition ) {
        return ((ScalarTypeDefinition)def).getDirectives();
    } if ( def instanceof UnionTypeDefinition ) {
        return ((UnionTypeDefinition)def).getDirectives();
    } if ( def instanceof InputObjectTypeDefinition ) {
        return ((InputObjectTypeDefinition)def).getDirectives();
    } if ( def instanceof SchemaDefinition ) {
        return ((SchemaDefinition)def).getDirectives();
    }
    return Collections.emptyList();
}
 
Example #3
Source File: STModel.java    From graphql-apigen with Apache License 2.0 6 votes vote down vote up
public synchronized List<String> getImports() {
    if ( null == imports ) {
        Definition def = typeEntry.getDefinition();
        Set<String> names = new TreeSet<String>();
        if ( isObjectType() ) {
            addImports(names, (ObjectTypeDefinition)def);
        } else if ( isInterfaceType() ) {
            addImports(names, (InterfaceTypeDefinition)def);
        } else if ( isInputObjectType() ) {
            addImports(names, (InputObjectTypeDefinition)def);
        } else if ( isUnionType() ) {
            addImports(names, (UnionTypeDefinition)def);
        } else if ( isEnumType() ) {
            addImports(names, (EnumTypeDefinition)def);
        } else if ( isSchemaType() ) {
            addImports(names, (SchemaDefinition)def);
        }
        imports = new ArrayList<>(names);
    }
    return imports;
}
 
Example #4
Source File: STModel.java    From graphql-apigen with Apache License 2.0 6 votes vote down vote up
public synchronized List<Field> getFields() {
    if ( null == fields ) {
        Definition def = typeEntry.getDefinition();
        if ( isObjectType() ) {
            fields = getFields((ObjectTypeDefinition)def);
        } else if ( isInterfaceType() ) {
            fields = getFields((InterfaceTypeDefinition)def);
        } else if ( isInputObjectType() ) {
            fields = getFields((InputObjectTypeDefinition)def);
        } else if ( isUnionType() ) {
            fields = getFields((UnionTypeDefinition)def);
        } else if ( isEnumType() ) {
            fields = getFields((EnumTypeDefinition)def);
        } else if ( isSchemaType() ) {
            fields = getFields((SchemaDefinition)def);
        } else {
            fields = Collections.emptyList();
        }
    }
    return fields;
}
 
Example #5
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 #6
Source File: GqlParentType.java    From manifold with Apache License 2.0 5 votes vote down vote up
private void addInnerTypes( SrcLinkedClass srcClass )
{
  mapUnionMemberToUnions();

  for( TypeDefinition type: _registry.types().values() )
  {
    if( type instanceof ObjectTypeDefinition )
    {
      addInnerObjectType( (ObjectTypeDefinition)type, srcClass );
    }
    else if( type instanceof InterfaceTypeDefinition )
    {
      addInnerInterfaceType( (InterfaceTypeDefinition)type, srcClass );
    }
    else if( type instanceof EnumTypeDefinition )
    {
      addInnerEnumType( (EnumTypeDefinition)type, srcClass );
    }
    else if( type instanceof InputObjectTypeDefinition )
    {
      addInnerInputType( (InputObjectTypeDefinition)type, srcClass );
    }
    else if( type instanceof UnionTypeDefinition )
    {
      addInnerUnionType( (UnionTypeDefinition)type, srcClass );
    }
  }
}
 
Example #7
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 #8
Source File: GqlParentType.java    From manifold with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unused")
private String getStartSymbol( Node node )
{
  String start = "";
  if( node instanceof TypeDefinition )
  {
    if( node instanceof ObjectTypeDefinition )
    {
      start = "type";
    }
    else if( node instanceof EnumTypeDefinition )
    {
      start = "enum";
    }
    else if( node instanceof InputObjectTypeDefinition )
    {
      start = "input";
    }
    else if( node instanceof InterfaceTypeDefinition )
    {
      start = "interface";
    }
    else if( node instanceof ScalarTypeDefinition )
    {
      start = "scalar";
    }
    else if( node instanceof UnionTypeDefinition )
    {
      start = "union";
    }
  }
  else if( node instanceof OperationDefinition )
  {
    start = ((OperationDefinition)node).getOperation().name().toLowerCase();
  }
  return start;
}
 
Example #9
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 #10
Source File: STModel.java    From graphql-apigen with Apache License 2.0 4 votes vote down vote up
public boolean isEnumType() {
    return typeEntry.getDefinition() instanceof EnumTypeDefinition;
}
 
Example #11
Source File: STModel.java    From graphql-apigen with Apache License 2.0 4 votes vote down vote up
private void addImports(Collection<String> imports, EnumTypeDefinition def) {
    // No imports should be necessary...
}