How can you setup graphene-sqlalchemy to filter an object by id?
I'd like to run the query:
{
marker(markerId: 1) {
markerId
title
}
}
I would expect to get a single Marker object where markerId is 1, but I get the error "Unknown argument "markerId" on field "marker" of type "Query"."
I have two files:
schema.py
import graphene
from graphene_sqlalchemy import SQLAlchemyObjectType
from model import db_session, Marker as MarkerModel
class Marker(SQLAlchemyObjectType):
class Meta:
model = MarkerModel
class Query(graphene.ObjectType):
marker = graphene.Field(Marker)
markers = graphene.List(Marker)
def resolve_markers(self, args, context, info):
return db_session.query(MarkerModel).all()
def resolve_marker(self, args, context, info):
return db_session.query(MarkerModel).first()
schema = graphene.Schema(query=Query)
model.py
import sqlalchemy as db
from sqlalchemy.orm import scoped_session, sessionmaker
from sqlalchemy.ext.declarative import declarative_base
from instance.config import settings
engine = db.create_engine(settings["SQLALCHEMY_DATABASE_URI"])
sm = sessionmaker(bind=engine)
db_session = scoped_session(sm)
Base = declarative_base()
Base.query = db_session.query_property()
class Marker(Base):
__tablename__ = "marker"
marker_id = db.Column(db.Integer, primary_key=True)
latitude = db.Column(db.Float)
longitude = db.Column(db.Float)
title = db.Column(db.String(100))
blurb = db.Column(db.String(65535))
def __repr__(self):
return "<Marker %d: %s>".format([self.marker_id, self.title])
Thanks for your help!
I haven't worked with the sql-alchemy, but I suppose you have to add Node interface to your model like: