Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.1.0 new selectionSetInitializers not being generated for named fragments #2940

Closed
BrentMifsud opened this issue Apr 6, 2023 · 3 comments
Closed
Labels
bug Generally incorrect behavior needs investigation

Comments

@BrentMifsud
Copy link

BrentMifsud commented Apr 6, 2023

Summary

my named fragments do not seem to be getting inits generated after adding the following to my configuration:

"selectionSetInitializers" : {
      "operations": true,
      "namedFragments": true,
      "localCacheMutations" : true
}

Here is an example fragment and its generated code:

fragment EmployeeFragment on Employee {
    id
    email
    name
    phoneNumber
    profilePictureUrl
    favorite
    hideFromEmployeeSchedule
    signInStatus
}
// @generated
// This file was automatically generated and should not be edited.

@_exported import ApolloAPI
import EnvoyMobile

struct EmployeeFragment: EnvoySchema.SelectionSet, Fragment {
  public static var fragmentDefinition: StaticString { """
    fragment EmployeeFragment on Employee {
      __typename
      id
      email
      name
      phoneNumber
      profilePictureUrl
      favorite
      hideFromEmployeeSchedule
      signInStatus
    }
    """ }

  public let __data: DataDict
  public init(_dataDict: DataDict) { __data = _dataDict }

  public static var __parentType: ApolloAPI.ParentType { EnvoySchema.Objects.Employee }
  public static var __selections: [ApolloAPI.Selection] { [
    .field("__typename", String.self),
    .field("id", Int.self),
    .field("email", String?.self),
    .field("name", String.self),
    .field("phoneNumber", String?.self),
    .field("profilePictureUrl", String?.self),
    .field("favorite", Bool.self),
    .field("hideFromEmployeeSchedule", Bool.self),
    .field("signInStatus", Bool.self),
  ] }

  public var id: Int { __data["id"] }
  public var email: String? { __data["email"] }
  public var name: String { __data["name"] }
  public var phoneNumber: String? { __data["phoneNumber"] }
  public var profilePictureUrl: String? { __data["profilePictureUrl"] }
  public var favorite: Bool { __data["favorite"] }
  public var hideFromEmployeeSchedule: Bool { __data["hideFromEmployeeSchedule"] }
  public var signInStatus: Bool { __data["signInStatus"] }
}

in fact there is no difference in the generated results by adding or removing selectionSetInitializers from my config.

Version

1.1.0

Steps to reproduce the behavior

Project is not open source, so I can't share it.

My configuration is as follows:

{
  "schemaName" : "EnvoySchema",
  "input" : {
    "operationSearchPaths" : [
      "EnvoyMobile/Modules/GraphQL/Fragments/*.graphql",
      "EnvoyMobile/Modules/GraphQL/Mutations/*.graphql",
      "EnvoyMobile/Modules/GraphQL/Queries/*.graphql"
    ],
    "schemaSearchPaths" : [
      "EnvoyMobile/Modules/GraphQL/schema.graphqls"
    ]
  },
  "output" : {
    "testMocks" : {
      "none" : {
      }
    },
    "schemaTypes": {
      "moduleType": {
          "embeddedInTarget": {
            "name": "EnvoyMobile"
          }
      },
      "path": "EnvoyMobile/Modules/GraphQL/Generated/Schema/"
    },
    "operations" : {
      "absolute" : {
        "path": "EnvoyMobile/Modules/GraphQL/Generated/Operations"
      }
    },
    "selectionSetInitializers" : {
      "operations": true,
      "namedFragments": true,
      "localCacheMutations" : true
    },
    "deprecatedEnumCases": "include",
    "schemaDocumentation": "include",
    "warningsOnDeprecatedUsage": "include",
    "conversionStrategies": {
        "enumCases": "camelCase"
    },
    "pruneGeneratedFiles": true
  }
}

I tried deleting apollo entirely, nuking my SPM cache, and re adding it, along with regenerating the CLI (just in case it was some old cached version of the cli). Does not seem to be helping.

Logs

No response

Anything else?

I am using Apollo with SPM

@BrentMifsud BrentMifsud added bug Generally incorrect behavior needs investigation labels Apr 6, 2023
@AnthonyMDev
Copy link
Contributor

AnthonyMDev commented Apr 6, 2023

Thanks for the report @BrentMifsud!

It looks like you've got a bug in your config file. Everything from selectionSetInitializers down should be in an options object. So your config should look like this:

{
  "schemaName" : "EnvoySchema",
  "input" : {
    "operationSearchPaths" : [
      "EnvoyMobile/Modules/GraphQL/Fragments/*.graphql",
      "EnvoyMobile/Modules/GraphQL/Mutations/*.graphql",
      "EnvoyMobile/Modules/GraphQL/Queries/*.graphql"
    ],
    "schemaSearchPaths" : [
      "EnvoyMobile/Modules/GraphQL/schema.graphqls"
    ]
  },
  "output" : {
    "testMocks" : {
      "none" : {
      }
    },
    "schemaTypes": {
      "moduleType": {
          "embeddedInTarget": {
            "name": "EnvoyMobile"
          }
      },
      "path": "EnvoyMobile/Modules/GraphQL/Generated/Schema/"
    },
    "operations" : {
      "absolute" : {
        "path": "EnvoyMobile/Modules/GraphQL/Generated/Operations"
      }
    },
  }
  "options": {
      "selectionSetInitializers" : {
        "operations": true,
        "namedFragments": true,
        "localCacheMutations" : true
      },
      "deprecatedEnumCases": "include",
      "schemaDocumentation": "include",
      "warningsOnDeprecatedUsage": "include",
      "conversionStrategies": {
          "enumCases": "camelCase"
      },
      "pruneGeneratedFiles": true
   }
}

Our codegen engine should probably be catching this problem and alerting you to the error though. @calvincestari Should we create an issue for improving that validation?

@calvincestari
Copy link
Member

Our codegen engine should probably be catching this problem and alerting you to the error though. @calvincestari Should we create an issue for improving that validation?

Definitely should be catching something like this and warning about it.

@BrentMifsud
Copy link
Author

Ahhhh that explains it. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Generally incorrect behavior needs investigation
Projects
None yet
Development

No branches or pull requests

3 participants