1

Graphql Schema Mutations happen to use the default DB specified in settings.py. Since I have a Django project with multiple apps and db's , how can I specify graphql mutation to use a different db and not the default one.

class CreateCategory(graphene.Mutation):
    class Arguments:
        name = graphene.String(required=True)
        slug = graphene.String(required=True)

    category = graphene.Field(CategoryType)

    @classmethod
    def mutate(cls, root, info, name, slug):
        category = Category()
        category.name = name
        category.slug = slug
        print(category)
        try:
            category.save()
        except:
            traceback.print_exc()
        return CreateCategory(category=category)
Mansi Shah
  • 227
  • 2
  • 6

1 Answers1

0

If all of it GraphQL models are in a single app, consider using Django’s database routers: https://docs.djangoproject.com/en/4.1/topics/db/multi-db/

FlipperPA
  • 13,607
  • 4
  • 39
  • 71