How to use the apollo-codegen-core/lib/compiler/visitors/collectAndMergeFields.collectAndMergeFields function in apollo-codegen-core

To help you get started, we’ve selected a few apollo-codegen-core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github apollographql / apollo-tooling / packages / apollo-codegen-swift / src / helpers.ts View on Github external
propertiesForSelectionSet(
    selectionSet: SelectionSet,
    namespace?: string
  ): (Field & Property & Struct)[] | undefined {
    const properties = collectAndMergeFields(selectionSet, true)
      .filter(field => field.name !== "__typename")
      .map(field => this.propertyFromField(field, namespace));

    // If we're not merging in fields from fragment spreads, there is no guarantee there will a generated
    // type for a composite field, so to avoid compiler errors we skip the initializer for now.
    if (
      selectionSet.selections.some(
        selection => selection.kind === "FragmentSpread"
      ) &&
      properties.some(property => isCompositeType(getNamedType(property.type)))
    ) {
      return undefined;
    }

    return properties;
  }
github apollographql / apollo-tooling / packages / apollo-codegen-swift / src / codeGeneration.ts View on Github external
swift`public private(set) var resultMap: ResultMap`
        );

        this.printNewlineIfNeeded();
        this.printOnNewline(swift`public init(unsafeResultMap: ResultMap)`);
        this.withinBlock(() => {
          this.printOnNewline(swift`self.resultMap = unsafeResultMap`);
        });

        if (typeCase) {
          this.initializersForTypeCase(typeCase);
        } else {
          this.initializersForVariant(variant);
        }

        const fields = collectAndMergeFields(
          variant,
          !!mergeInFieldsFromFragmentSpreads
        ).map(field => this.helpers.propertyFromField(field as Field));

        const fragmentSpreads = variant.fragmentSpreads.map(fragmentSpread => {
          const isConditional = variant.possibleTypes.some(
            type => !fragmentSpread.selectionSet.possibleTypes.includes(type)
          );

          return this.helpers.propertyFromFragmentSpread(
            fragmentSpread,
            isConditional
          );
        });

        fields.forEach(this.propertyDeclarationForField, this);
github apollographql / apollo-tooling / packages / apollo-codegen-typescript / src / codeGeneration.ts View on Github external
private getPropertiesForVariant(variant: Variant): ObjectProperty[] {
    const fields = collectAndMergeFields(
      variant,
      this.context.options.mergeInFieldsFromFragmentSpreads
    );
    return fields.map(field => {
      const fieldName = field.alias !== undefined ? field.alias : field.name;
      this.scopeStackPush(fieldName);

      let res: ObjectProperty;
      if (field.selectionSet) {
        res = this.handleFieldSelectionSetValue(
          t.identifier(this.nameFromScopeStack(this.scopeStack)),
          field
        );
      } else {
        res = this.handleFieldValue(field, variant);
      }
github apollographql / apollo-tooling / packages / apollo-codegen-flow / src / codeGeneration.ts View on Github external
private getPropertiesForVariant(variant: Variant): ObjectProperty[] {
    const fields = collectAndMergeFields(
      variant,
      this.context.options.mergeInFieldsFromFragmentSpreads
    );

    return fields.map(field => {
      const fieldName = field.alias !== undefined ? field.alias : field.name;
      this.scopeStackPush(fieldName);

      let res;
      if (field.selectionSet) {
        const generatedTypeName = this.annotationFromScopeStack(
          this.scopeStack
        );
        res = this.handleFieldSelectionSetValue(generatedTypeName, field);
      } else {
        res = this.handleFieldValue(field, variant);