Java Code Examples for graphql.schema.idl.TypeDefinitionRegistry#types()
The following examples show how to use
graphql.schema.idl.TypeDefinitionRegistry#types() .
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: GraphQLSchemaDefinition.java From carbon-apimgt with Apache License 2.0 | 6 votes |
/** * Extract GraphQL Operations from given schema * @param schema graphQL Schema * @return the arrayList of APIOperationsDTOextractGraphQLOperationList * */ public List<URITemplate> extractGraphQLOperationList(String schema, String type) { List<URITemplate> operationArray = new ArrayList<>(); SchemaParser schemaParser = new SchemaParser(); TypeDefinitionRegistry typeRegistry = schemaParser.parse(schema); Map<java.lang.String, TypeDefinition> operationList = typeRegistry.types(); for (Map.Entry<String, TypeDefinition> entry : operationList.entrySet()) { if (entry.getValue().getName().equals(APIConstants.GRAPHQL_QUERY) || entry.getValue().getName().equals(APIConstants.GRAPHQL_MUTATION) || entry.getValue().getName().equals(APIConstants.GRAPHQL_SUBSCRIPTION)) { if (type == null) { addOperations(entry, operationArray); } else if (type.equals(entry.getValue().getName().toUpperCase())) { addOperations(entry, operationArray); } } } return operationArray; }
Example 2
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; }