graphql-code-generator | generating code based on a GraphQL schema | GraphQL library

 by   dotansimha TypeScript Version: release-1685631366501 License: MIT

kandi X-RAY | graphql-code-generator Summary

kandi X-RAY | graphql-code-generator Summary

graphql-code-generator is a TypeScript library typically used in Web Services, GraphQL, React applications. graphql-code-generator has no bugs, it has no vulnerabilities, it has a Permissive License and it has medium support. You can download it from GitHub.

GraphQL Code Generator is a tool that generates code out of your GraphQL schema. Whether you are developing a frontend or backend, you can utilize GraphQL Code Generator to generate output from your GraphQL Schema and GraphQL Documents (query/mutation/subscription/fragment). By analyzing the schema and documents and parsing it, GraphQL Code Generator can output code at a wide variety of formats, based on pre-defined templates or based on custom user-defined ones. Regardless of the language that you're using, GraphQL Code Generator got you covered. GraphQL Code Generator lets you choose the output that you need, based on plugins, which are very flexible and customizable. You can also write your plugins to generate custom outputs that match your needs. You can try this tool live on your browser and see some useful examples. Check out GraphQL Code Generator Live Examples. We currently support and maintain these plugins (TypeScript, Flow, React, Angular, MongoDB, Stencil, Reason, and some more), and there is an active community that writes and maintains custom plugins.
Support
    Quality
      Security
        License
          Reuse

            kandi-support Support

              graphql-code-generator has a medium active ecosystem.
              It has 10068 star(s) with 1244 fork(s). There are 81 watchers for this library.
              There were 4 major release(s) in the last 12 months.
              There are 399 open issues and 1991 have been closed. On average issues are closed in 87 days. There are 62 open pull requests and 0 closed requests.
              It has a neutral sentiment in the developer community.
              The latest version of graphql-code-generator is release-1685631366501

            kandi-Quality Quality

              graphql-code-generator has no bugs reported.

            kandi-Security Security

              graphql-code-generator has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.

            kandi-License License

              graphql-code-generator is licensed under the MIT License. This license is Permissive.
              Permissive licenses have the least restrictions, and you can use them in most projects.

            kandi-Reuse Reuse

              graphql-code-generator releases are available to install and integrate.
              Installation instructions, examples and code snippets are available.

            Top functions reviewed by kandi - BETA

            kandi's functional review helps you automatically verify the functionalities of the libraries and avoid rework.
            Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of graphql-code-generator
            Get all kandi verified functions for this library.

            graphql-code-generator Key Features

            No Key Features are available at this moment for graphql-code-generator.

            graphql-code-generator Examples and Code Snippets

            No Code Snippets are available at this moment for graphql-code-generator.

            Community Discussions

            QUESTION

            What is a correct return type of a GraphQL resolve function?
            Asked 2022-Feb-04 at 20:57

            I faced with an issue that can't resolve on my own. Let's go through it step by step to point out the problem.

            1. I have a mutation bookAppointment which returns an Appointment object
            2. GraphQL schema says that this object should return 4 properties: id, date, specialist, client.
            3. To follow the GraphQL-style the specialist and client properties should be a field level resolvers
            4. To fetch this objects I need pass specialistId to the specialist field level resolver, as well as clientId to the client field level resolver.
            5. At this point a problem arises.
            6. The field level resolvers of client, specialist expects that root mutation returns fields like clientId and specialistId. But GraphQL syntax and types that were generated by that syntax doesn't include this props (make sense).
            7. How to "extend" the return type of the resolver and its interface BookAppointmentPayload to make me and TypeScript happy?

            This is my GraphQL schema

            ...

            ANSWER

            Answered 2022-Feb-04 at 20:57

            I've been investigating this problem quite a lot and have come to the following conclusion.

            Create an interface which represent "actual" return type of the resolver

            Most of the time the return type of the resolver function (in JavaScript) doesn't match the type that was declared in the GraphQL SDL

            For instance,

            Source https://stackoverflow.com/questions/70925556

            QUESTION

            How to map a custom scalar type to a typescript type when using graphql code generator?
            Asked 2021-Oct-04 at 07:45

            A custom scalar type named Date which is an ISO 8601 string is defined in the backend.

            In the frontend "GraphQL Code Generator" (https://www.graphql-code-generator.com/) is used to generate typescript types from the schema.

            The codegen.yml looks like this:

            ...

            ANSWER

            Answered 2021-Oct-03 at 02:33

            Codegen doesn't do anything for conversion, you could put Date: number and it would happily print that in your generated file. It is really just a way to automatically generate Typescript types for your API.

            What you are looking for is different, you basically need a "middleware" from you graphql client that:

            1. Has access to the schema. So this means you need to be comfortable shipping your whole schema with your frontend application, which most developers are not especially for private APIs.
            2. Can parse said schema to match fields in the JSON response to scalars and then interpret them into whatever native type your want (like Date)

            For the Apollo client, you can use https://github.com/eturino/apollo-link-scalars. For urql, I found https://github.com/clentfort/urql-custom-scalars-exchange.

            Source https://stackoverflow.com/questions/69408456

            QUESTION

            How to use Apollo Rover + Codegen to generate typescript schema types
            Asked 2021-Sep-26 at 16:51

            I am struggling to understand how to use Apollo Rover in conjunction with Apollo Codegen to generate my typescript types for my API's schema. I registered my schema in apollo studio, and can grab the schema into a GQL file, but it looks like codegen is not supported in the Rover CLI and so I need to use the legacy Apollo CLI. However the Apollo CLI wants schema to be fetched from a remote endpoint and not a registered schema, and wants the schema in JSON format, but Rover only fetches in .gql format.

            I'm confused about how I am "supposed" to hook this up so that I can use apollo codegen with my registered schema without a bunch of manual conversion work.

            ...

            ANSWER

            Answered 2021-Sep-26 at 16:51

            I found this. I think you should keep use Apollo CLI.

            Rover does not currently provide client-specific features, such as code generation or client checks. For these features, continue using the Apollo CLI.

            Another solution use, it work for me ;)

            https://github.com/dotansimha/graphql-code-generator

            Source https://stackoverflow.com/questions/69287539

            QUESTION

            What is the purpose of the `Exact` type that @graphql-codegen creates?
            Asked 2021-Sep-21 at 14:14

            GraphQL Code Generator creates this type on the top of the created TypeScript file:

            ...

            ANSWER

            Answered 2021-Sep-21 at 14:14

            It aims to make it so that one cannot pass an object with any additional properties (in addition to id) as FooQueryVariables. But it fails to do so: https://github.com/dotansimha/graphql-code-generator/issues/4577

            Source https://stackoverflow.com/questions/69268390

            QUESTION

            Use RTK Query with Graphql
            Asked 2021-Jun-03 at 16:03

            So far I understand I need to build my own baseQuery. I could write graphql queries and mutations like in example here https://rtk-query-docs.netlify.app/examples/react-with-graphql, will I get full type safety for queries and mutations if I add types to query.builder like this builder.query or I must use something like this https://www.graphql-code-generator.com/docs/plugins/typescript-graphql-request#simple-request-middleware. In latter case how should my baseQuery look if I use generated hook for graphql-request library.

            Here is example of hook from 2:

            ...

            ANSWER

            Answered 2021-Jun-03 at 16:03

            Actually I started writing a plugin for the code generator a few days ago. You can see the generated result here: https://github.com/phryneas/graphql-code-generator/blob/5f9a2eefd81538782b791e0cc5df633935164a89/dev-test/githunt/types.rtk-query.ts#L406-L427

            This would require you to create an api with a baseQuery using a graphql library of your choice like this.

            A configuration would look like this

            Source https://stackoverflow.com/questions/67793393

            QUESTION

            Gatsby page query returns undefined
            Asked 2021-May-14 at 04:59

            I have a Gatsby page component and try to query some data from GraphCMS. I added the page component inside a folder:

            ...

            ANSWER

            Answered 2021-May-14 at 04:59

            Your allGraphCmsProject information it's inside props.data.allGraphCmsProject so the resultant structure should be:

            Source https://stackoverflow.com/questions/67526113

            QUESTION

            How to write a TypeScript type utility that narrows union types in an object?
            Asked 2021-Feb-08 at 17:10

            I've got a bunch of generated types (via GraphQL codegen) that look like this:

            ...

            ANSWER

            Answered 2021-Feb-08 at 17:10

            It's a bit tricky to tease union members apart from each other, and I'm not 100% sure about the general use case, but here's one way you might approach it:

            Source https://stackoverflow.com/questions/66105845

            QUESTION

            How to generate Typescript definitions from AppSync GraphQL schema if I am not using amplify?
            Asked 2020-Dec-17 at 15:40

            I have my AppSync api set up using aws-cdk and am not using their amplify framework. I am trying to figure out how / if I can generate Typescript definitions from my AppSync schema.graphql file while not using amplify, i.e. no access to amplify codegen command. I did try installing and running it, but I assume amplify expects files to be located in certain directories, hence failing.

            I looked into https://graphql-code-generator.com but it wont work due to special types AppSync uses like AWSDateTime, a work around for this is to have api published and get schema from a graphql endpoint, but this is not ideal i.e. I'd like to be able and generate these types locally without publishing the schema.

            Is this doable?

            ...

            ANSWER

            Answered 2020-Dec-17 at 15:40

            If there's some custom scalars (like AWSDateTime) that aren't part of your schema.graphql file, you can just create a separate file like scalars.graphql and add those missing type definitions yourself:

            Source https://stackoverflow.com/questions/65342101

            QUESTION

            Select graphql data with useResult on nested properties
            Asked 2020-Dec-01 at 13:52

            We have a graphql query that is executed like this:

            ...

            ANSWER

            Answered 2020-Dec-01 at 13:52

            Figured it out. we only needed to check the __typename property before returning the object data 'array':

            Source https://stackoverflow.com/questions/65091330

            QUESTION

            Are array types incorrect when generating React/Apollo hooks with graphql-code-generator?
            Asked 2020-Nov-10 at 18:03

            I am wondering if arrays defined in graphql queries/mutations, which can be either singletons or tuples in valid graphql implementation get converted to strict array types by graphql-codegen. Is this is by design ?

            Given this schema:

            ...

            ANSWER

            Answered 2020-Nov-10 at 18:03

            GraphQL inputs in operations supports coercion, but codegen doesn't (see: https://github.com/dotansimha/graphql-code-generator/issues/4888) We are working on it and hope to fix that in upcoming versions ;)

            Source https://stackoverflow.com/questions/64774182

            Community Discussions, Code Snippets contain sources that include Stack Exchange Network

            Vulnerabilities

            No vulnerabilities reported

            Install graphql-code-generator

            You can find the complete instructions in GraphQL-Code-Generator website. Start by installing the basic deps of GraphQL Codegen;.

            Support

            Besides our docs page, feel free to go through our published Medium articles to get a better grasp of what GraphQL Code Generator is all about:.
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries
            CLONE
          • HTTPS

            https://github.com/dotansimha/graphql-code-generator.git

          • CLI

            gh repo clone dotansimha/graphql-code-generator

          • sshUrl

            git@github.com:dotansimha/graphql-code-generator.git

          • Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link

            Explore Related Topics

            Consider Popular GraphQL Libraries

            parse-server

            by parse-community

            graphql-js

            by graphql

            apollo-client

            by apollographql

            relay

            by facebook

            graphql-spec

            by graphql

            Try Top Libraries by dotansimha

            graphql-yoga

            by dotansimhaTypeScript

            envelop

            by dotansimhaTypeScript

            graphql-eslint

            by dotansimhaTypeScript

            graphql-binding

            by dotansimhaTypeScript