I am trying to get character fields from the api rest of Rick&Morty using graphql with Fastapi + StrawBerry and i always get the same error with the first field i write
my code:
from fastapi import FastAPI
import strawberry
from strawberry.fastapi import GraphQLRouter
import requests
@strawberry.type
class Character:
id: int
name: str
status: str
species: str
@strawberry.type
class Query:
@strawberry.field
def getIdent(self, ch: str) -> Character:
url = f'https://rickandmortyapi.com/api/character/{ch}'
return requests.get(url).json()
app = FastAPI()
schema = strawberry.Schema(Query)
graphql_app = GraphQLRouter(schema)
app.include_router(graphql_app, prefix="/graphql")
my graphql query:
query MyQuery {
getIdent(ch: "2") {
name
species
}
}
and the error:
{
"data": null,
"errors": [
{
"message": "'dict' object has no attribute 'name'",
"locations": [
{
"line": 3,
"column": 5
}
],
"path": [
"getIdent",
"name"
]
}
]
}