Skip to content

[zod-graphql-client] Confusion regardings types of variables #236

@jellelicht

Description

@jellelicht

In your docs you have the following example:

const schema = z
    .object({
        // Provide graphql-specific metadata to your zod schema
        foo: graphqlFieldOptions(z.string(), {
            parameters: {
                bar: variablePlaceholder('$bar')
            }
        })
    })
    .strict();

// Send the query using the client
const client = createGraphqlClient({ endpoint: 'https://example.com/graphql' });
const result = await client.query(schema, {
    operationName: 'YourQueryName', // Optional query name
    variables: {
        bar: {
            type: 'String!',
            value: 'the-actual-value-for-bar'
        }
    }
});

What puzzles me is that the type of the variable is only 'defined' when running the query.
How would I be able to have the String! here be part of the schema, instead of the OperationOptions?

And would it subsequently be possible to have (limited) type-safe variables as well (e.g., make it impossible to pass value: 22 for bar in this example)?

If none of this is in-scope for these libraries, please feel free to close this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions