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.

Create many mutation not connecting relationships

See original GitHub issue

When I run a createMany mutation with multiple objects connecting to the same user only one of the objects is added to the users relationship.

All of the posts however have a relationship to the user.

I would expect the user to relate to all of the posts not just one.

   const userId = existingItem._id.toString();

    const posts = postsData.map(post => ({
        data: {
          author: { connect: { id: userId } }
        }
     }));

    await actions.query(
      `mutation CreatePosts($posts: [PostsCreateInput]) {
        createPosts(data: $posts) {
          id
          author {
            id
          }
        }
      }`,
      { variables: { posts } }
    );

hypothesis: this is occurring because the connect runs in parallel and so the last post overrides the previous connect attempts.

This issue should not occur if I was to run multiple createSingle mutations in a loop.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
SeanDoyleGitcommented, Nov 11, 2019

Here are the schemas

const User = {
  fields: {
    name: { type: Text },
    posts: {
      type: Relationship,
      ref: 'Posts.author',
      many: true
    },
  }
}
const Post = {
  fields: {
    name: { type: Text },
    author: {
      type: Relationship,
      ref: 'User.posts',
    },
  }
}
0reactions
timlesliecommented, Apr 9, 2020

I have run some experiments and confirmed that the Arcade release has resolved this issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Ability to connect if exists, otherwise create in GraphQL ...
Hello there, I'm wondering if it would be possible to implement some kind of upsert but for relational connections in mutations.
Read more >
Auto-generated Mutation Does Not Create Relationship
Hello, I want to test auto-generated CRUD operations created by calling makeAugmentedSchema. There is no problem with creating nodes but - 23850.
Read more >
How to create mutation with 3 or more nested relationships?
I do the following in the schema.graphql: type Mutation { createClient (input: createClientInput! @spread): Client @create } input ...
Read more >
Using GraphQL Mutations to Manage Model Relationships
Those are, create, connect, reconnect and disconnect. So, we're going to jump into the API Explorer and just play around with these to...
Read more >
Mutation with relationships - Atlas GraphQL API - MongoDB
So one Recipe has a one-to-many relationship with its Ingredients which have keys [_id, name]. How do I build the AddRecipeMutation?
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