Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I generate exportable graphql input types using amplify codegen? #44

Open
timrchavez opened this issue Mar 9, 2019 · 6 comments
Labels
doc-gen Issues on graphql-doc-generator feature-request New feature or request p4 plugins-support

Comments

@timrchavez
Copy link

** Which Category is your question related to? **

codegen

** What AWS Services are you utilizing? **

appsync, dynamodb

** Provide additional details e.g. code snippets **

I'm trying to follow the documentation here https://aws-amplify.github.io/docs/js/api#aws-appsync-sdk and there is an example for using buildMutation given:

import { listTodos } from './graphql/queries';
import { createTodo, CreateTodoInput } from './graphql/mutations';

(async () => {
  const result = await client.mutate(buildMutation(client,
    gql(createTodo),
    {
      inputType: gql(CreateTodoInput),
      variables: {
        input: {
          name: 'Use AppSync',
          description: 'Realtime and Offline',
        }
      }
    },
    (_variables) => [ gql(listTodos) ],
    'Todo'));

  console.log(result);
})();

Specifically, import { createTodo, CreateTodoInput } from './graphql/mutations';

When I run amplify codegen, the generated src/graphql/mutations.js does not include input types (e.g. CreateTodoInput in the case of the example given). How do I generate these, so I can use buildMutation in a similar manner?

Just noticed I used aws instead of amplify everywhere. My bad :) aws mindshare is strong

@yuth
Copy link
Contributor

yuth commented Mar 12, 2019

codegen does not generate input types, but its needed for offline support. We will have to update the codegen to generate input types to make it easier to support offline support

@jkeys-ecg-nmsu
Copy link

@yuth could the input types generated by AppSync be downloaded with something like amplify api pull --types?

@yuth
Copy link
Contributor

yuth commented Mar 12, 2019

@jkeys-ecg-nmsu the compiled schema should already be available to you inside <proj-root>/amplify/backedn/api/<api-name>/build/schema.json and should have the input type.

I have added this issue to our backlog to generate input types. I will try to get to this as soon as this gets prioritized.

@timrchavez timrchavez changed the title How do I generate exportable graphql input types using aws codegen? How do I generate exportable graphql input types using amplify codegen? Mar 13, 2019
@Alonitor
Copy link

It seams that you can pass the entire schema into the "inputType":

import schemaGraphQL from "../../../../../amplify/backend/api/[project name]/build/schema.graphql"

then:

 makePost() {
      return (async () => {
        const result = await this.$apollo.provider.defaultClient.mutate(
          buildMutation(
            this.$apollo.provider.defaultClient,
            gql(require("@/graphql/mutations.js").createPost),
            {
              inputType: schemaGraphQL, 
              variables: {
                input: {
                  title: "My post",
                  content: "This is the post",
                }
              }
            },
            _variables => [gql(require("@/graphql/queries.js").listPosts)],
            "listPosts",
            "CreatePostInput",
            "id",
            "AUTO"
          )
        );

        console.log(result);
      })();
    },

And Im using the graphql-tag/loader: https:/apollographql/graphql-tag

It seams not to work with the schema.json file...

I'm not sure if this is a good idea or not? But the goal must be to define everything once in schema.graphql and reuse everything from there on.

@apoorvmote
Copy link

Set input type manually as follows. It works.

inputType: gql(`input CreateTodoInput {
          id: ID
          name: String!
        }`),

@AaronZyLee AaronZyLee transferred this issue from aws-amplify/amplify-cli Jan 29, 2021
@phani-srikar
Copy link
Contributor

Hi @timrchavez .The input types are generated for typescript and flow targets during amplify codegen add workflow. Would be awesome if you could take advantage of those in the meantime.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc-gen Issues on graphql-doc-generator feature-request New feature or request p4 plugins-support
Projects
None yet
Development

No branches or pull requests

7 participants