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

Mutations support #47

Open
simonw opened this issue Aug 14, 2020 · 5 comments
Open

Mutations support #47

simonw opened this issue Aug 14, 2020 · 5 comments
Labels
enhancement New feature or request

Comments

@simonw
Copy link
Owner

simonw commented Aug 14, 2020

Supporting mutations for inserting / updating data is a very useful next step.

@simonw simonw added the enhancement New feature or request label Aug 14, 2020
@simonw
Copy link
Owner Author

simonw commented Aug 14, 2020

It would be good to be able to detect if a table has an auto-incrementing primary key - if it does, an insert can be supported by providing the non-primary-key columns. If not, then inserts will also need to include the desired primary key.

@simonw
Copy link
Owner Author

simonw commented Dec 3, 2020

Graphene docs: https://docs.graphene-python.org/en/latest/types/mutations/

import graphene

class CreatePerson(graphene.Mutation):
    class Arguments:
        name = graphene.String()

    ok = graphene.Boolean()
    person = graphene.Field(lambda: Person)

    def mutate(root, info, name):
        person = Person(name=name)
        ok = True
        return CreatePerson(person=person, ok=ok)

class Person(graphene.ObjectType):
    name = graphene.String()
    age = graphene.Int()

class MyMutations(graphene.ObjectType):
    create_person = CreatePerson.Field()

# We must define a query for our schema
class Query(graphene.ObjectType):
    person = graphene.Field(Person)

schema = graphene.Schema(query=Query, mutation=MyMutations)

Then:

mutation m {
    createPerson(name:"Peter") {
        person {
            name
        }
        ok
    }
}

@simonw
Copy link
Owner Author

simonw commented Dec 6, 2020

Maybe the configuration that defines these should use YAML (or JSON) strings containing the GraphQL type language.

https://graphql.org/learn/schema/

input ReviewInput {
  stars: Int!
  commentary: String
}

@simonw
Copy link
Owner Author

simonw commented Dec 6, 2020

The graphql-core library (which graphene already depends on) has a parser for the GraphQL language: https://github.com/graphql-python/graphql-core/blob/master/src/graphql/language/parser.py

@simonw
Copy link
Owner Author

simonw commented Jan 23, 2023

Datasette 1.0 alpha has JSON write APIs now, which could help inform the design and implementation of this:

https://docs.datasette.io/en/1.0a2/json_api.html#the-json-write-api

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant