错误' tuple'对象没有属性' obs -python graphql草莓+ Fastapi
我正在启动一个GraphQL项目,在其中创建一个API以从Informix数据库中获取数据。 我设法使一切正常工作,但我无法获得任何结果,相反,我
'tuple' object has no attribute 'obs
会得到任何帮助!
这是我
[main.py]
from fastapi import FastAPI
from schema import graphql_app
app = FastAPI()
app.include_router(graphql_app, prefix='/bitola')
[schema.py]
from typing import Optional, List
import strawberry
import datetime
from strawberry.fastapi import GraphQLRouter
from dbfunctions import get_bitola
@strawberry.type
class Bitola:
cod_bitola: Optional[int]
des_abr_bitola: str
des_bitola: str
qtd_largura: int
data_insercao: datetime.datetime
data_alteracao: datetime.datetime
obs: str
@strawberry.type
class Query:
allBitolas: List[Bitola] = strawberry.field(resolver=get_bitola)
schema = strawberry.Schema(query=Query)
graphql_app = GraphQLRouter(schema, graphiql=True, allow_queries_via_get=False)
[dbfunctions.py]
import jaydebeapi
def get_bitola():
conn = jaydebeapi.connect("com.informix.jdbc.IfxDriver",
"jdbc:informix-sqli://ifxserver:INFORMIXSERVER=ifxdv",
["user", "pass"],
"/path/to/jdbcdriver/informix-jdbc-complete-4.50.4.1.jar")
curs = conn.cursor()
curs.execute('select * from bitola')
ldb = curs.fetchall()
curs.close()
conn.close()
return ldb
进行测试时
hypercorn main:app
,我转到localhost:8000/bitola
并输入查询,
{
allBitolas {
obs
}
}
我收到了错误消息
{
"data": null,
"errors": [
{
"message": "'tuple' object has no attribute 'obs'",
"locations": [
{
"line": 3,
"column": 5
}
],
"path": [
"allBitolas",
0,
"obs"
]
}
]
}
,我可以理解原因。
请提供所有帮助和指针!
I'm starting a graphql project where I'm creating an API to get data from an Informix database.
I've managed to get everything working but I can't get any results and instead I get the error
'tuple' object has no attribute 'obs
Any help would be appreciated!
This is what I have
[main.py]
from fastapi import FastAPI
from schema import graphql_app
app = FastAPI()
app.include_router(graphql_app, prefix='/bitola')
[schema.py]
from typing import Optional, List
import strawberry
import datetime
from strawberry.fastapi import GraphQLRouter
from dbfunctions import get_bitola
@strawberry.type
class Bitola:
cod_bitola: Optional[int]
des_abr_bitola: str
des_bitola: str
qtd_largura: int
data_insercao: datetime.datetime
data_alteracao: datetime.datetime
obs: str
@strawberry.type
class Query:
allBitolas: List[Bitola] = strawberry.field(resolver=get_bitola)
schema = strawberry.Schema(query=Query)
graphql_app = GraphQLRouter(schema, graphiql=True, allow_queries_via_get=False)
[dbfunctions.py]
import jaydebeapi
def get_bitola():
conn = jaydebeapi.connect("com.informix.jdbc.IfxDriver",
"jdbc:informix-sqli://ifxserver:INFORMIXSERVER=ifxdv",
["user", "pass"],
"/path/to/jdbcdriver/informix-jdbc-complete-4.50.4.1.jar")
curs = conn.cursor()
curs.execute('select * from bitola')
ldb = curs.fetchall()
curs.close()
conn.close()
return ldb
When testing with
hypercorn main:app
i go to localhost:8000/bitola
and input the query
{
allBitolas {
obs
}
}
i get the error message
{
"data": null,
"errors": [
{
"message": "'tuple' object has no attribute 'obs'",
"locations": [
{
"line": 3,
"column": 5
}
],
"path": [
"allBitolas",
0,
"obs"
]
}
]
}
and I can't understand why.
TY for all the help and pointers!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我正在使用的lib(jaydebeapi),cursor.fetchall()返回一个元组列表,而解析器需要返回Bitola实例列表。因此,对于从DB调用返回的列表中的每个成员,我需要将其转换为一个实例。
所以我做到了,它是按预期的。
在
The lib i'm using (jaydebeapi), cursor.fetchAll() returns a list of tuples, whereas the resolver needs to return a list of instances of Bitola. So for each member in the list returned from the db call, I need to transform it into an instance.
So I did and it's working as intendend.
Answered on Reddit