npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

codegen-apollo-client-executor

v1.0.0

Published

Generate typesafe apollo client instances

Downloads

3

Readme

Apollo Client Executor

This is a plugin for graphl codegen, it is designed for use with apollo in places where hooks cannot be used.

The reason i created this project is because i had a html table which would do things like create modals and fore mutations from cells.
Due to the way the project was setup everything was passed in as an object keyed by an enum value including the on submit handlers which needed to mutate.

export const config = {
    [Enum.MemberA]: {
        label: 'First',
        modalTitle: 'First',
        onSubmit: data => {
            /* The problem */
        },
    },
    [Enum.MemberB]: {
        label: 'Second',
        modalTitle: 'Second',
        onSubmit: data => {
            /* The problem */
        },
    }
    ...
};

This worked very well for the project but due to the rules of hooks they could not be used. The short term solution was to execute against a apollo client directly which could be done with typesafety however it needed to be done manually.

import {GetAllPeopleDocument, MutationType, MutationVariablesType} from './generated.tsx';

const response = await client.query<MutationType, MutationVariablesType>({
    query: GetAllPeopleDocument,
    variables: {
        pageSize: 5
    },
})

We already had these really nice typesafe hooks so why couldn't we generate some nice typesafe clients?

Thats what this plugin is designed to do so you get nice typed outputs like this.

const response = await queryGetAllPeopleQuery(client, {
    variables: {
        pageSize: 5
    }
})

or

const response = await graphQlClient(client)
    .query
    .getAllPeople({
        variables: {
            pageSize: 5
        },
    }

Example

yarn add -D codegen-apollo-client-executor

Below is an example codegen.yml

schema: "https://swapi-graphql.netlify.app/.netlify/functions/index"
overwrite: true
documents: src/**/*.graphql
generates:
  src/generated/client.tsx:
    - "typescript"
    - "typescript-operations"
    - "codegen-apollo-client-executor"