amplify-cli icon indicating copy to clipboard operation
amplify-cli copied to clipboard

Custom query

Open rudyhadoux opened this issue 5 months ago • 3 comments

Amplify CLI Version

13.0.1

Question

Hi, In the documentation here https://docs.amplify.aws/gen1/angular/build-a-backend/graphqlapi/custom-business-logic/

There is that type Mutation { myCustomMutation(args: String): String # your custom mutations here }

type Query { myCustomQuery(args: String): String # your custom queries here }

Is it possible to put a complete example please ?

rudyhadoux avatar Jun 28 '25 14:06 rudyhadoux

That is a working example.

export const getUser2 = /* GraphQL */ `query GetUser($id: ID!) {
  getUser(id: $id) {
    Stripe_customer_ID
    name
  }
}
` as GeneratedQuery<
  APITypes.GetUserQueryVariables,
  APITypes.GetUserQuery
>;

    let utilisateur: any = await this.client.graphql({
      query: getUser2,
      variables: {
        id: user_ID!,
      },
      authMode: 'userPool',
    });


rudyhadoux avatar Jun 30 '25 08:06 rudyhadoux

Current vs Expected Behavior

Current Documentation State:

type Mutation {
  myCustomMutation(args: String): String # your custom mutations here
}

type Query {
  myCustomQuery(args: String): String # your custom queries here
}

Working Example (from comments):

export const getUser2 = /* GraphQL */ `query GetUser($id: ID!) {
  getUser(id: $id) {
    Stripe_customer_ID
    name
  }
}
` as GeneratedQuery<
  APITypes.GetUserQueryVariables,
  APITypes.GetUserQuery
>;

let utilisateur: any = await this.client.graphql({
  query: getUser2,
  variables: {
    id: user_ID!,
  },
  authMode: 'userPool',
});

Expected Documentation Enhancement: The documentation should include complete, working examples that show:

  1. Schema definition with custom queries/mutations
  2. TypeScript implementation using GraphQL client
  3. Proper type annotations and variable handling
  4. Authentication mode configuration
  5. Integration with Angular applications

Hi @rudyhadoux,

Thank you for this documentation enhancement request! You're absolutely right that the current custom business logic documentation could benefit from more complete implementation examples.

I can see from your comment that you've already found a working solution using the GraphQL client with proper TypeScript annotations - that's exactly the kind of complete example that would be valuable to include in the official documentation.

This is a great suggestion for improving the developer experience. The documentation team should consider adding:

  • Complete schema-to-implementation examples
  • TypeScript/Angular-specific code samples
  • Different authentication mode patterns
  • Integration with Angular services and components

Would you be interested in contributing a pull request to enhance the documentation? The Amplify docs are open source and community contributions are always welcome! You could help other developers by sharing the working patterns you've discovered.

The documentation repository is at https://github.com/aws-amplify/docs and the relevant file would be in the Gen1 Angular section.

pahud avatar Aug 20 '25 16:08 pahud

Sorry but I don't have enough time.

But, several comments : These custom GraphQL queries allow you to obtain a lot of objects with a limited number of members : useful for calculating sums or averages on a particular member. Or custom filters with limited number of members result.

I made another issue regarding photo management for Angular with an NgOptimizedImage provider (S3), it concerns Amplify Storage. The only solution I have found is to manage publicly accessible photos with a fixed S3 directory.

rudyhadoux avatar Aug 20 '25 16:08 rudyhadoux