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

Inserting an item with Graphql and also getting an error #2491

Closed
2 tasks done
Themrpie opened this issue Apr 23, 2024 · 3 comments
Closed
2 tasks done

Inserting an item with Graphql and also getting an error #2491

Themrpie opened this issue Apr 23, 2024 · 3 comments
Labels
pending-response pending-triage question Further information is requested

Comments

@Themrpie
Copy link

How did you install the Amplify CLI?

npm

If applicable, what version of Node.js are you using?

No response

Amplify CLI Version

12.11.1

What operating system are you using?

Mac

Did you make any manual changes to the cloud resources managed by Amplify? Please describe the changes made.

No

Describe the bug

For some reason when I insert an object in my table it works well but I also get an error message.
And when I query a particular object I get the same error. Hopefully somebody can see what I'm doing wrong. I'm using graphql from amplify.

The problem is being cause by the category field of Service, because when I remove it or change it to a String in the schema everything goes well.

I also noted that when I query a particular service I get the same error. I don't know why.

Expected behavior

I should not get an error

Reproduction steps

Create app with
npx create-expo-app appname -t expo-template-blank-typescript
install amplify with these instructions:
https://docs.amplify.aws/react-native/start/getting-started/setup/#create-a-new-project

Use the schema included in this post.
Record an object using the function included in this post.

Project Identifier

90e248fdd5b64aad8ace95f42eba4110

Log output

# Put your logs below this line
"Cannot return null for non-nullable type: 'AWSDateTime' within parent 'Category' (/createService/category/createdAt)" "Cannot return null for non-nullable type: 'AWSDateTime' within parent 'Category' (/createService/category/updatedAt)

Additional information

This is my schema:

type Category @model 
  @auth(rules: [{ allow: public, operations: [read, update, create] }, { allow: owner, operations: [read, update, create] }]) {
  id: ID!
  name: String!
  services: [Service] @hasMany
}
type Service @model 
  @auth(rules: [{ allow: public, operations: [read] }, { allow: owner }]) {
  id: ID!
  category: Category @belongsTo
  title: String!
  description: String!
  price: Int!  
  seller: Seller @hasOne  
}

And this is how I'm recording into the db:

const addJob = async() => {
        // const cardId = uuid();
        setLoading(true);
        const jobDetails: CreateServiceInput = {
            title: data.title,
            description: data.description,
            price: parseInt(data.price),
            sellerServicesId: userID,
            categoryServicesId: 'e4322408-91f1-7076-0e4f-e5a81dt602b6' 
        }
        try {
            const response = await client.graphql({
                query: createService,
                variables: { input: jobDetails},
                
            })
            console.log('response: ', response);
            // navigation.navigate('HomeScreen', {msg:'added'});
        } catch (error : any) {
            console.log('error: ', error)
            // Alert.alert(error?.message)
        } finally {
            setLoading(false);
        }       
      }

Codegen auto generates this function thats being used by addJob function:

[Unable to insert an item with Graphql](https://stackoverflow.com/questions/78369304/unable-to-insert-an-item-with-graphql)

Before submitting, please confirm:

  • I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
  • I have removed any sensitive information from my code snippets and submission.
@phani-srikar
Copy link
Contributor

Hi @Themrpie, can you check that the Category record with id e4322408-91f1-7076-0e4f-e5a81dt602b6 that the Service belongs to, has createdAt and updatedAt fields set by querying it?

@AnilMaktala AnilMaktala added the question Further information is requested label May 9, 2024
@AnilMaktala
Copy link

Hey 👋 , This issue is being closed due to inactivity. If you are still experiencing the same problem and need further assistance, please feel free to leave a comment. This will enable us to reopen the issue and provide you with the necessary support.

Copy link

This issue is now closed. Comments on closed issues are hard for our team to see.
If you need more assistance, please open a new issue that references this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pending-response pending-triage question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants