@ SuppressWarnings ( "unchecked" ) public Document createSchemaDefinition ( Map < String , Object > introspectionResult ) { assertTrue ( introspectionResult . get ( "__schema" ) != null , "__schema expected" ) ; Map < String , Object > schema = ( Map < String , Object > ) introspectionResult . get ( "__schema" ) ; Map < String , Object > queryType = ( Map < String , Object > ) schema . get ( "queryType" ) ; assertNotNull ( queryType , "queryType expected" ) ; TypeName query = TypeName . newTypeName ( ) . name ( ( String ) queryType . get ( "name" ) ) . build ( ) ; boolean nonDefaultQueryName = ! "Query" . equals ( query . getName ( ) ) ; SchemaDefinition . Builder schemaDefinition = SchemaDefinition . newSchemaDefinition ( ) ; schemaDefinition . operationTypeDefinition ( OperationTypeDefinition . newOperationTypeDefinition ( ) . name ( "query" ) . typeName ( query ) . build ( ) ) ; Map < String , Object > mutationType = ( Map < String , Object > ) schema . get ( "mutationType" ) ; boolean nonDefaultMutationName = false ; if ( mutationType != null ) { TypeName mutation = TypeName . newTypeName ( ) . name ( ( String ) mutationType . get ( "name" ) ) . build ( ) ; nonDefaultMutationName = ! "Mutation" . equals ( mutation . getName ( ) ) ; schemaDefinition . operationTypeDefinition ( OperationTypeDefinition . newOperationTypeDefinition ( ) . name ( "mutation" ) . typeName ( mutation ) . build ( ) ) ; } Map < String , Object > subscriptionType = ( Map < String , Object > ) schema . get ( "subscriptionType" ) ; boolean nonDefaultSubscriptionName = false ; if ( subscriptionType != null ) { TypeName subscription = TypeName . newTypeName ( ) . name ( ( ( String ) subscriptionType . get ( "name" ) ) ) . build ( ) ; nonDefaultSubscriptionName = ! "Subscription" . equals ( subscription . getName ( ) ) ; schemaDefinition . operationTypeDefinition ( OperationTypeDefinition . newOperationTypeDefinition ( ) . name ( "subscription" ) . typeName ( subscription ) . build ( ) ) ; } Document . Builder document = Document . newDocument ( ) ; if ( nonDefaultQueryName || nonDefaultMutationName || nonDefaultSubscriptionName ) { document . definition ( schemaDefinition . build ( ) ) ; } List < Map < String , Object > > types = ( List < Map < String , Object > > ) schema . get ( "types" ) ; for ( Map < String , Object > type : types ) { TypeDefinition typeDefinition = createTypeDefinition ( type ) ; if ( typeDefinition == null ) continue ; document . definition ( typeDefinition ) ; } return document . build ( ) ; }
Returns a IDL Document that reprSesents the schema as defined by the introspection result map