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

[ApolloCodegen] Support for multiple headers #1131

Closed
LachlanMcCulloch opened this issue Apr 8, 2020 · 5 comments
Closed

[ApolloCodegen] Support for multiple headers #1131

LachlanMcCulloch opened this issue Apr 8, 2020 · 5 comments
Labels
codegen Issues related to or arising from code generation
Milestone

Comments

@LachlanMcCulloch
Copy link

Currently, in ApolloCodegen you can only initialize ApolloSchemaOptions with a single header property, which is translated to --header="<HEADER>". Since the Apollo CLI allows for multiple headers arguments (... --header=<HEADER1> --header=<HEADER2>), I was wondering if it would be possible to implement this in this tool?

One potential way, albeit a breaking change, is to do the following:

let headers: [String]
...
  public init(schemaFileName: String = "schema",
              schemaFileType: SchemaFileType = .json,
              apiKey: String? = nil,
              endpointURL: URL,
              headers: [String] = [],
              outputFolderURL: URL,
              downloadTimeout: Double = 30.0) {
    self.apiKey = apiKey
    self.headers = headers
    self.endpointURL = endpointURL
    self.outputURL = outputFolderURL.appendingPathComponent("\(schemaFileName).\(schemaFileType.rawValue)")
    	
    self.downloadTimeout = downloadTimeout
  }

...
for header in headers {
    arguments.append("--header='\(header)'")
}

This changes header to an array of headers instead and provides the same logic to append extra headers to the end of the CLI call.

I've tested this with a forked repo and it appears to still work, of course after updating any implementations to use headers, instead of header:
LachlanMcCulloch@fe5d417

Let me know if you need any more supporting information or clarification.

Cheers! :)

@designatednerd
Copy link
Contributor

Yep this is exactly why this is still in Beta. 😃

Wanna open a PR?

@designatednerd designatednerd added the codegen Issues related to or arising from code generation label Apr 8, 2020
@LachlanMcCulloch
Copy link
Author

@designatednerd - sure can!
#1153

@designatednerd
Copy link
Contributor

Awesome, thank you!

@designatednerd designatednerd added this to the Next Release milestone Apr 15, 2020
@LachlanMcCulloch
Copy link
Author

Thanks @designatednerd 😄

@designatednerd
Copy link
Contributor

This has shipped with 0.26.0!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
codegen Issues related to or arising from code generation
Projects
None yet
Development

No branches or pull requests

2 participants