graphql-python / graphql-python/graphql-core-legacy

Abstract type must resolve to an Object type at runtime for field Query error

Aperta
#106 0 commenti 5 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
Python
Stelle
372
Fork
175
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

I am trying to use unions and see the above error. Any help appreciated. Here's the schema:

```
schema {
query: Query
}
union Address = L3 | L2
type L2 {
mac: String
}
type L3 {
ip: String
}
type Query {
address(t: String): Address
}
```
Here's the example code:

```
import graphql, sys, json

class Query(object):
def resolve_address(self, args, context, info):
typ = args.get('t')
if typ == "L3":
return '10.1.1.10'
else:
return '00:aa:bb:cc:dd:ee'
######################################################################

def resolve_fn(obj, args, context, info):
# If obj is a mapping, return obj[field_name], else if
# obj.resolve_field_name() exists call it, else return obj.field_name.
field_name = info.field_name
if hasattr(obj, '__getitem__'):
return obj[field_name]
rfn = getattr(obj, "resolve_%s" % field_name, None)
if rfn and callable(rfn):
return rfn(args, context, info)
else:
return getattr(obj, field_name)

class MiddlewareManager(graphql.MiddlewareManager):
def get_field_resolver(self, field_resolver):
return resolve_fn
######################################################################

query = '{address(t:"L2"){... on L3{ip} ...on L2{mac}}}'

schema_source = open('schema.graphql').read()
schema = graphql.build_ast_schema(graphql.parse(schema_source))

r = graphql.graphql(schema, query,
root_value=Query(),
context_value=123,
middleware=MiddlewareManager())
print "errors:", r.errors
print "data:", r.data
print "json:", json.dumps(r.data)
```
Similar example written in Graphene works fine but I would like to use schema written in native grpahql format.

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Direzione di ricerca

Inizia eseguendo l’esempio schema.graphql fornito tramite graphql.build_ast_schema e graphql.graphql, quindi analizza la risoluzione a runtime per l’unione Address restituita da Query.resolve_address. Il lavoro è completato quando la query termina senza l’errore relativo al tipo astratto e produce i dati L2/L3 previsti.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
api
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Da chiarire
Idoneità per principianti
25/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.