How can I generate the auth
parameter using the bal graphql
command? When I run bal graphql --help
, I don’t see any options. Do I need to manually modify the generated code?
I have generated the GraphQL client using the latest version of Ballerina and it creates a record named public type ConnectionConfig
record. How can I set the authentication for the client using tokenUrl
, clientId
and clientSecret
within this record?
1 Answer
Currently, the code generation supports only four types of authentication configurations:
- No auth
- API key config
- Bearer-token/Basic Auth config
- API key config & bearer-token/Basic Auth config
In this context, you need to add the extensions
section in the GraphQL config file with the relevant tokens and headers. These values are used when generating the client. It is mandatory to configure the schema
section with the web URL of the GraphQL schema, as shown below.
schema: <The web URL of the GraphQL schema.>
documents:
- <File path to the GraphQL document with the GraphQL queries & mutations>
extensions:
endpoints:
default:
headers: { "Authorization": "Bearer token", "API_Header_Key1": "API_Header_Value1", "API_Header_Key2": "API_Header_Value2" }
At the moment, OAuth2
grant configurations are not supported to be passed as parameters during code generation. It has to be included manually after the code generation. For more details, check this example.