How to configure baseOptions as required? #4887
-
Generated hooks have the field I am using version 2.0.7 of graphql-codegen/typescript-react-apollo with apollo/client version 3.2.2. My types: type Query {
todo(id: Long!): Todo!
}
type Todo {
id: Long
description: String
done: Boolean
} My query: query Todo($id: Long!) {
todo(id: $id) {
description,
done
}
} Generated function: export function useTodoQuery(baseOptions?: Apollo.QueryHookOptions<TodoQuery, TodoVariables>) {
return Apollo.useQuery<TodoQuery, TodoVariables>(TodoDocument, baseOptions);
} Call the hook: // query with required parameter:
const { loading, error, data } = useTodoQuery({ variables: {id: 1}})
// query without required parameter:
const { loading, error, data } = useTodoQuery() // no error, because baseOptions are optional -> but I do want an error if i have to hand parameters over |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
I think you are right, @anderha . This should have better typings configured, and maybe if there are required variables it should not be optional and make sure developers pass the variables (because all the other configurations are really always optional). |
Beta Was this translation helpful? Give feedback.
I think you are right, @anderha . This should have better typings configured, and maybe if there are required variables it should not be optional and make sure developers pass the variables (because all the other configurations are really always optional).
Can you please report this as an issue?