/** * Helper to construct a new root query with the given attributes and 'empty' * route/variables. */ static build( name: string, fieldName: string, value: mixed, children: ?Array<RelayQueryNode>, metadata: ConcreteQueryMetadata, type: string, routeName?: string, ): RelayQueryRoot { const nextChildren = children ? children.filter(child => !!child) : []; const batchCallVariable = QueryBuilder.getBatchCallVariable(value); let identifyingArgValue; if (batchCallVariable) { identifyingArgValue = batchCallVariable; } else if (Array.isArray(value)) { identifyingArgValue = value.map(QueryBuilder.createCallValue); } else if (value) { identifyingArgValue = QueryBuilder.createCallValue(value); } const concreteRoot = QueryBuilder.createQuery({ fieldName, identifyingArgValue, metadata, name, type, }); const variables = {}; const metaRoute = RelayMetaRoute.get(routeName || '$RelayQuery'); const rootContext = createRootContext(metaRoute, variables); const root = new RelayQueryRoot(concreteRoot, rootContext, variables); root.__children__ = nextChildren; return root; }
} else { identifyingArgValue = QueryBuilder.createCallValue( identifyingArg.value ); } } } const children = node.getChildren().map(toGraphQLSelection); // Use `QueryBuilder` to generate the correct calls from the // identifying argument & metadata. return QueryBuilder.createQuery({ children, fieldName: node.getFieldName(), identifyingArgValue, isDeferred: node.isDeferred(), metadata: node.getConcreteQueryNode().metadata, name: node.getName(), type: node.getType(), }); }, Fragment(node: RelayQuery.Fragment): ConcreteFragment { const children = node.getChildren().map(toGraphQLSelection); const fragment: ConcreteFragment = { children, kind: 'Fragment', metadata: { isAbstract: node.isAbstract(), plural: node.isPlural(), }, name: node.getDebugName(),