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

graphql-gen-request

v1.2.3

Published

the simple way gen the graphql request ql

Downloads

3

Readme

声明

该解决方案是一种违背了 graphql 按需获取的本意,对于 graphql 初次接入的前端同学提供自动生成的 graphql request 代码。 由于该程序并不能揣测开发者对 graphql 按需的本意,所以将 graphql 的返回值按照 depth 深度进行按照深度返回全量的 schema,减少大家拼写 gql 的难度。

建议

希望大家在对 graphql 基本数量的情况下按照 graphql 按需拿去的本意进行重构代码,该工具暂当应急使用。

使用方式:

yarn add graphql-gen-request -global
gqlgenreq --remote http://xxxxx/graphql --destDirPath ./  --maxLevel 3

Example

schema

type Mutation {
  CreatePerson(person: PersonCreate): Person
}

type Person {
  ID: Int!
  Name: String!
  Age: Int!
}

input PersonCreate {
  Name: String!
  Aage: Int!
}

type Query {
  getPersonByID(ID: Int!): Person
}

output:

import { GraphQLClient } from 'graphql-request';
import { print } from 'graphql';
import gql from 'graphql-tag';
export type Maybe<T> = T | null;
/** All built-in and custom scalars, mapped to their actual values */
export type Scalars = {
  ID: string;
  String: string;
  Boolean: boolean;
  Int: number;
  Float: number;
};

export type Mutation = {
   __typename?: 'Mutation';
  CreatePerson?: Maybe<Person>;
};


export type MutationCreatePersonArgs = {
  person?: Maybe<PersonCreate>;
};

export type Person = {
   __typename?: 'Person';
  ID: Scalars['Int'];
  Name: Scalars['String'];
  Age: Scalars['Int'];
};

export type PersonCreate = {
  Name: Scalars['String'];
  Aage: Scalars['Int'];
};

export type Query = {
   __typename?: 'Query';
  getPersonByID?: Maybe<Person>;
};


export type QueryGetPersonByIdArgs = {
  ID: Scalars['Int'];
};

export type CreatePersonMutationVariables = {
  person?: Maybe<PersonCreate>;
};


export type CreatePersonMutation = (
  { __typename?: 'Mutation' }
  & { CreatePerson?: Maybe<(
    { __typename?: 'Person' }
    & Pick<Person, 'ID' | 'Name' | 'Age'>
  )> }
);

export type GetPersonByIdQueryVariables = {
  ID: Scalars['Int'];
};


export type GetPersonByIdQuery = (
  { __typename?: 'Query' }
  & { getPersonByID?: Maybe<(
    { __typename?: 'Person' }
    & Pick<Person, 'ID' | 'Name' | 'Age'>
  )> }
);


export const CreatePersonDocument = gql`
    mutation CreatePerson($person: PersonCreate) {
  CreatePerson(person: $person) {
    ID
    Name
    Age
  }
}
    `;
export const GetPersonByIdDocument = gql`
    query getPersonByID($ID: Int!) {
  getPersonByID(ID: $ID) {
    ID
    Name
    Age
  }
}
    `;

export type SdkFunctionWrapper = <T>(action: () => Promise<T>) => Promise<T>;


const defaultWrapper: SdkFunctionWrapper = sdkFunction => sdkFunction();
export function getSdk(client: GraphQLClient, withWrapper: SdkFunctionWrapper = defaultWrapper) {
  return {
    CreatePerson(variables?: CreatePersonMutationVariables): Promise<CreatePersonMutation> {
      return withWrapper(() => client.request<CreatePersonMutation>(print(CreatePersonDocument), variables));
    },
    getPersonByID(variables: GetPersonByIdQueryVariables): Promise<GetPersonByIdQuery> {
      return withWrapper(() => client.request<GetPersonByIdQuery>(print(GetPersonByIdDocument), variables));
    }
  };
}
export type Sdk = ReturnType<typeof getSdk>;