void setChildrenContexts(Map<String, List<TraverserContext<T>>> children) { assertTrue(this.children == null, "children already set"); this.children = children; }
StringPathSegment(String value) { assertTrue(value != null && !value.isEmpty(), "empty path component"); this.value = value; }
public DefaultConnectionCursor(String value) { Assert.assertTrue(value != null && !value.isEmpty(), "connection value cannot be null or empty"); this.value = value; }
public NodeMultiZipper<T> withReplacedZipper(NodeZipper<T> oldZipper, NodeZipper<T> newZipper) { int index = zippers.indexOf(oldZipper); assertTrue(index >= 0, "oldZipper not found"); List<NodeZipper<T>> newZippers = new ArrayList<>(zippers); newZippers.set(index, newZipper); return new NodeMultiZipper<>(commonRoot, newZippers, this.nodeAdapter); }
public SimpleListConnection(List<T> data, String prefix) { this.data = assertNotNull(data, " data cannot be null"); assertTrue(prefix != null && !prefix.isEmpty(), "prefix cannot be null or empty"); this.prefix = prefix; }
private String node(Node node, Class startClass) { if (startClass != null) { assertTrue(startClass.isInstance(node), "The starting class must be in the inherit tree"); } StringWriter sw = new StringWriter(); PrintWriter out = new PrintWriter(sw); NodePrinter<Node> printer = _findPrinter(node, startClass); printer.print(out, node); return sw.toString(); }
private void assertNonNullWrapping(GraphQLType wrappedType) { assertTrue(!GraphQLTypeUtil.isNonNull(wrappedType), String.format("A non null type cannot wrap an existing non null type '%s'", GraphQLTypeUtil.simplePrint(wrappedType))); }
@Internal public NodeParentTree(Deque<T> nodeStack) { assertNotNull(nodeStack, "You MUST have a non null stack of nodes"); assertTrue(!nodeStack.isEmpty(), "You MUST have a non empty stack of nodes"); Deque<T> copy = new ArrayDeque<>(nodeStack); path = mkPath(copy); node = copy.pop(); if (!copy.isEmpty()) { parent = Optional.of(new NodeParentTree<T>(copy)); } else { parent = Optional.empty(); } }
/** * The exception to the general rule is the system __xxxx Introspection fields which have no parent type and * are able to be specified on any type * * @param fieldName the name of the system field which MUST start with __ * * @return the coordinates */ public static FieldCoordinates systemCoordinates(String fieldName) { assertTrue(fieldName.startsWith("__"), "Only __ system fields can be addressed without a parent type"); assertValidName(fieldName); return new FieldCoordinates(null, fieldName); } }
private CompletableFuture<Publisher<Object>> createSourceEventStream(ExecutionContext executionContext, ExecutionStrategyParameters parameters) { ExecutionStrategyParameters newParameters = firstFieldOfSubscriptionSelection(parameters); CompletableFuture<FetchedValue> fieldFetched = fetchField(executionContext, newParameters); return fieldFetched.thenApply(fetchedValue -> { Object publisher = fetchedValue.getFetchedValue(); if (publisher != null) { assertTrue(publisher instanceof Publisher, "You data fetcher must return a Publisher of events when using graphql subscriptions"); } //noinspection unchecked return (Publisher<Object>) publisher; }); }
@SuppressWarnings("unchecked") InterfaceTypeDefinition createInterface(Map<String, Object> input) { assertTrue(input.get("kind").equals("INTERFACE"), "wrong input"); InterfaceTypeDefinition.Builder interfaceTypeDefinition = InterfaceTypeDefinition.newInterfaceTypeDefinition().name((String) input.get("name")); interfaceTypeDefinition.comments(toComment((String) input.get("description"))); List<Map<String, Object>> fields = (List<Map<String, Object>>) input.get("fields"); interfaceTypeDefinition.definitions(createFields(fields)); return interfaceTypeDefinition.build(); }
@SuppressWarnings("unchecked") InputObjectTypeDefinition createInputObject(Map<String, Object> input) { assertTrue(input.get("kind").equals("INPUT_OBJECT"), "wrong input"); InputObjectTypeDefinition.Builder inputObjectTypeDefinition = InputObjectTypeDefinition.newInputObjectDefinition() .name((String) input.get("name")) .comments(toComment((String) input.get("description"))); List<Map<String, Object>> fields = (List<Map<String, Object>>) input.get("inputFields"); List<InputValueDefinition> inputValueDefinitions = createInputValueDefinitions(fields); inputObjectTypeDefinition.inputValueDefinitions(inputValueDefinitions); return inputObjectTypeDefinition.build(); }
@SuppressWarnings("unchecked") UnionTypeDefinition createUnion(Map<String, Object> input) { assertTrue(input.get("kind").equals("UNION"), "wrong input"); UnionTypeDefinition.Builder unionTypeDefinition = UnionTypeDefinition.newUnionTypeDefinition(); unionTypeDefinition.name((String) input.get("name")); unionTypeDefinition.comments(toComment((String) input.get("description"))); List<Map<String, Object>> possibleTypes = (List<Map<String, Object>>) input.get("possibleTypes"); for (Map<String, Object> possibleType : possibleTypes) { TypeName typeName = TypeName.newTypeName().name((String) possibleType.get("name")).build(); unionTypeDefinition.memberType(typeName); } return unionTypeDefinition.build(); }
/** * Called to place system data fetchers (eg Introspection fields) into the mix * * @param coordinates the field coordinates * @param dataFetcher the data fetcher code for that field * * @return this builder */ public Builder systemDataFetcher(FieldCoordinates coordinates, DataFetcher<?> dataFetcher) { assertNotNull(dataFetcher); assertNotNull(coordinates); assertTrue(coordinates.getFieldName().startsWith("__"), "Only __ system fields can be used here"); systemDataFetcherMap.put(coordinates.getFieldName(), DataFetcherFactories.useDataFetcher(dataFetcher)); return this; }
private static Map<String, Object> introspect(GraphQLSchema schema) { GraphQL gql = GraphQL.newGraphQL(schema).build(); ExecutionResult result = gql.execute(IntrospectionQuery.INTROSPECTION_QUERY); Assert.assertTrue(result.getErrors().size() == 0, "The schema has errors during Introspection"); return result.getData(); } }
@SuppressWarnings("unchecked") EnumTypeDefinition createEnum(Map<String, Object> input) { assertTrue(input.get("kind").equals("ENUM"), "wrong input"); EnumTypeDefinition.Builder enumTypeDefinition = EnumTypeDefinition.newEnumTypeDefinition().name((String) input.get("name")); enumTypeDefinition.comments(toComment((String) input.get("description"))); List<Map<String, Object>> enumValues = (List<Map<String, Object>>) input.get("enumValues"); for (Map<String, Object> enumValue : enumValues) { EnumValueDefinition.Builder enumValueDefinition = EnumValueDefinition.newEnumValueDefinition().name((String) enumValue.get("name")); enumValueDefinition.comments(toComment((String) enumValue.get("description"))); createDeprecatedDirective(enumValue, enumValueDefinition); enumTypeDefinition.enumValueDefinition(enumValueDefinition.build()); } return enumTypeDefinition.build(); }
private CompletableFuture<List<NodeZipper<ExecutionResultNode>>> fetchAndAnalyze(ExecutionContext executionContext, List<NodeZipper<ExecutionResultNode>> unresolvedNodes) { assertTrue(unresolvedNodes.size() > 0, "unresolvedNodes can't be empty"); List<FieldSubSelection> fieldSubSelections = map(unresolvedNodes, node -> util.createFieldSubSelection(executionContext, node.getCurNode().getFetchedValueAnalysis())); //constrain: all fieldSubSelections have the same mergedSelectionSet MergedSelectionSet mergedSelectionSet = fieldSubSelections.get(0).getMergedSelectionSet(); List<CompletableFuture<List<FetchedValueAnalysis>>> fetchedValues = batchFetchForEachSubField(executionContext, fieldSubSelections, mergedSelectionSet); return mapBatchedResultsBack(unresolvedNodes, fetchedValues); }
public ExecutionPath sibling(String siblingField) { Assert.assertTrue(!ROOT_PATH.equals(this), "You MUST not call this with the root path"); return new ExecutionPath(this.parent, new StringPathSegment(siblingField)); }
@Override public TraversalControl visitGraphQLUnionType(GraphQLUnionType node, TraverserContext<GraphQLType> context) { TypeResolver typeResolver = node.getTypeResolver(); if (typeResolver != null) { codeRegistry.typeResolverIfAbsent(node, typeResolver); } assertTrue(codeRegistry.getTypeResolver(node) != null, "You MUST provide a type resolver for the union type '" + node.getName() + "'"); return CONTINUE; } }
@Override public TraversalControl visitGraphQLInterfaceType(GraphQLInterfaceType node, TraverserContext<GraphQLType> context) { TypeResolver typeResolver = node.getTypeResolver(); if (typeResolver != null) { codeRegistry.typeResolverIfAbsent(node, typeResolver); } assertTrue(codeRegistry.getTypeResolver(node) != null, "You MUST provide a type resolver for the interface type '" + node.getName() + "'"); return CONTINUE; }