question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Override generated query

See original GitHub issue

Which Category is your question related to?

Graphql

Amplify CLI Version

6.0.0

What AWS Services are you utilizing?

Auth, Functions, Graphql, Storage

Provide additional details e.g. code snippets

I have a schema like this:

type Foo @model {
  id: ID!
  .... other attributes
}

I understand that on amplify push, I automatically get the type Query, with getFoo(id: ID). All well.

After a while, I wish to override this query - I want to use the @function directive to call a lambda function for this query only. How do I go about with it? When I tried to define it as:

type Query {
  getFoo(id: ID!): Foo @function(name: "blah")
}

I got the following error on amplify push :

Object type extension 'Query' cannot redeclare field getFoo
An error occurred during the push operation: Object type extension 'Query' cannot redeclare field getFoo

From what I see, I should rename the getFoo query to something else and then attach the function to it. I can no longer use getFoo itself… Is that right or there is a way to override?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
callmekatootiecommented, Oct 7, 2021

@yuth Thank you. Your approach worked. To summarize, in order to override the auto generated query, I had to first remove the existing auto generated one with:

type Foo @model(queries: { get: null, list: "listFoo" }) {
  id: ID!
}

# NOTE: No Query defined further. Just the model type definition above

Then I ran amplify push. After this ran successfully, I then introduced my overridden query:

type Foo @model(queries: { get: null, list: "listFoo" }) {
  id: ID!
}

# NOTE: Below has now been added newly. Above remains untouched
type Query {
   getFoo(id: ID!): Foo @function(name: "blah")
}

and ran amplify push again. This auto generated the listFoo query as well as allowed me to override the getFoo query.

My question has been answered. This issue can now be closed. Thank you for your timely assistance.

1reaction
yuthcommented, Oct 6, 2021

@PatrykMilewski you are right. When you override a query, mutation or a subscription, you will have to specify the field names of all the operations that you are not overriding. So in this case the schema will look like if you want the list query to be generated.

type Foo @model(queries: { get: null, list: "listFoo" }) {
  id: ID!
}

Read more comments on GitHub >

github_iconTop Results From Across the Web

API (GraphQL) - Overwrite & customize resolvers - Amplify Docs
Learn how to overwrite or add custom resolvers with Amplify. ... Create resolvers for newly created Query , Mutation or Subscription by creating...
Read more >
How do I overwrite SQL generated by a View? - InterWorks
There are several reasons to overwrite an SQL query generated by a view whether it's to improve performance or join to tables not...
Read more >
SQL Query Override - Informatica Documentation
SQL Query Override ... You can alter or override the default query in the mapping by entering SQL override in the Properties settings...
Read more >
Can I override Entity Framework query generator?
You don't need to override anything. Your best bet would be to just execute a plain SQL query through Entity Framework and have...
Read more >
Override default queries | Vue Storefront 2 for Magento
To override one or multiple queries without creating a custom composable for each usage, you can override the defaults ones with the customQueries...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found