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

How @import(module:) works? #3346

Closed
arnauddorgans opened this issue Feb 27, 2024 · 2 comments
Closed

How @import(module:) works? #3346

arnauddorgans opened this issue Feb 27, 2024 · 2 comments
Labels
question Issues that have a question which should be addressed

Comments

@arnauddorgans
Copy link
Contributor

Question

I saw in the latest release we can import modules from the definition line, but I need help understanding the purpose of being able to.

query SearchUsers($after: String, $username: String!) @import(module: "ProfileAPI") {
    searchSellersByUsername(first: 20, after: $after, username: $username) {
        edges {
            node {
                ...GQLUser
            }
        }
        totalCount
        pageInfo {
            endCursor
            hasNextPage
        }
    }
}

I have a fragment in ProfileAPI module named GQLUser but Apollo refuses to generate the file because Unknown fragment "GQLUser"
Is it supposed to work?

@arnauddorgans arnauddorgans added the question Issues that have a question which should be addressed label Feb 27, 2024
@BobaFetters
Copy link
Member

@arnauddorgans Based on what you posted I am assuming the GQLUser fragment (and ProfileAPI) are part of a separate schema from your SearchUsers query? The @import directive is used for handling Swift module imports based on how you have your code generation configured to output your files, not including items from a separate GraphQL schema into another.

The general use case is say you have your schema schema types (such as your fragments) generated into target/package A, while you may have various sets of operations that you have being generated into different modules B, C, and D, respectively. If you are using a fragment from A in an operation in package B, the generated code wouldn't compile without importing package A into the generated operation file in package B. Using this @import directive allows you to do this at the schema level and have it handled by code generation instead of having to do it manually.

Copy link
Contributor

Do you have any feedback for the maintainers? Please tell us by taking a one-minute survey. Your responses will help us understand Apollo iOS usage and allow us to serve you better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Issues that have a question which should be addressed
Projects
None yet
Development

No branches or pull requests

2 participants