Skip to content

Added ability to override how operation is serialized#89

Open
onionhammer wants to merge 4 commits into
lynxtaa:masterfrom
onionhammer:allow-custom-operation
Open

Added ability to override how operation is serialized#89
onionhammer wants to merge 4 commits into
lynxtaa:masterfrom
onionhammer:allow-custom-operation

Conversation

@onionhammer

@onionhammer onionhammer commented Dec 28, 2023

Copy link
Copy Markdown

Can be used to address #88

Example:

Bit ugly, but this at least makes using persisted queries possible:

	const client = new AwesomeGraphQLClient<string, RequestInit>({
		endpoint: server.endpoint,
		formatOperation: operation => {
			return JSON.stringify({
                                 ...operation,
				query: undefined,
				id: operation.query // <- pass the id as the argument to client.request instead of the raw graphql
			});
		},
	})

You could also institute logic in this callback to print() the document or pass the id if it exists on an object:

	const client = new AwesomeGraphQLClient<string, RequestInit>({
		endpoint: server.endpoint,
		formatOperation: operation => {
			const query = operation.query;

			return JSON.stringify({
                                 ...operation,
				query: "id" in query ? undefined : query,
				id: "id" in query ? query.id : undefined
			});
		},
	})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant