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

Inline fragment #97

Open
dcucchietti opened this issue Nov 26, 2024 · 0 comments
Open

Inline fragment #97

dcucchietti opened this issue Nov 26, 2024 · 0 comments
Labels
question Further information is requested

Comments

@dcucchietti
Copy link

Hi,

I'm trying to flatten fragments in my response models, but I'm encountering an issue where the fragments are wrapped in a nested object.

Here’s the GraphQL query I’m using:

fragment AuthenticationFragment on SessionInfo {
  role
  sessionGUID
  token
}

mutation loginAsGuest {
    login(
        lang: { key: "FRA" }
    ) {
        ...AuthenticationFragment
    }
}

The expected response (from a GraphQL client like Postman) is:

{
    "data": {
        "login": {
            "role": "XXX",
            "sessionGUID": "XXX",
            "token": "XXXX"
        }
    }
}

However, when using the Apollo Java Client, the response looks like this:

{
    "login": {
      "__typename": "SessionInfo",
      "authenticationFragment": {
        "role": {
          "rawValue": "XXX"
        },
        "sessionGUID": "XXX",
        "token": "XXX"
      }
    }
  }

As you can see, the fields of the AuthenticationFragment are nested inside the authenticationFragment object.

How can I remove the authenticationFragment wrapper and directly flatten the fields (role, sessionGUID, token) into the login object?

I have tried enabling the flattenModels option in the plugin configuration, but it didn’t work as expected.

Any missing configuration ?
Below my configuration :

<plugin>
                <groupId>com.github.aoudiamoncef</groupId>
                <artifactId>apollo-client-maven-plugin</artifactId>
                <version>7.1.0</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <services>
                                <test-api>
                                    <enabled>true</enabled>
                                    <addSourceRoot>true</addSourceRoot>
                                    <sourceFolder>${project.basedir}/src/test/resources/test</sourceFolder>
                                    <schemaPath>${project.basedir}/src/test/resources/test/schema.graphql
                                    </schemaPath>
                                    <includes>
                                        <include>**/*.gql</include>
                                    </includes>
                                    <compilationUnit>
                                        <name>test</name>
                                        <generateOperationDescriptors>true</generateOperationDescriptors>
                                        <compilerParams>
                                            <rootFolders>
                                                <rootFolder>${project.basedir}/src/test/resources/test/</rootFolder>
                                            </rootFolders>
                                            <scalarsMapping/>
                                            <schemaPackageName>fr.test.apollo.client</schemaPackageName>
                                            <packageName>fr.test.apollo.client</packageName>
                                            <codegenModels>OPERATION</codegenModels>
                                            <flattenModels>true</flattenModels>
                                            <generateApolloMetadata>false</generateApolloMetadata>
                                            <generateAsInternal>false</generateAsInternal>
                                            <generateFilterNotNull>false</generateFilterNotNull>
                                            <generateFragmentImplementations>false</generateFragmentImplementations>
                                            <generateKotlinModels>false</generateKotlinModels>
                                            <generateOptionalOperationVariables>false</generateOptionalOperationVariables>
                                            <generateQueryDocument>true</generateQueryDocument>
                                            <generateResponseFields>false</generateResponseFields>
                                            <generateSchema>false</generateSchema>
                                            <generateTestBuilders>false</generateTestBuilders>
                                            <generateDataBuilders>false</generateDataBuilders>
                                            <generateModelBuilders>false</generateModelBuilders>
                                            <nullableFieldStyle>NONE</nullableFieldStyle>
                                            <useSemanticNaming>true</useSemanticNaming>
                                            <targetLanguage>JAVA</targetLanguage>
                                            <sealedClassesForEnumsMatching></sealedClassesForEnumsMatching>
                                            <alwaysGenerateTypesMatching></alwaysGenerateTypesMatching>
                                            <metadataOutputFile>
                                                ${project.build.directory}/generated/metadata/apollo/test/metadata.json
                                            </metadataOutputFile>
                                        </compilerParams>
                                    </compilationUnit>
                                </test-api>
                            </services>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
@aoudiamoncef aoudiamoncef added the question Further information is requested label Nov 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants