Abstract type must resolve to an Object type at runtime for field Query error
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 25/100
Research direction
Start by running the provided schema.graphql example through graphql.build_ast_schema and graphql.graphql, then inspect runtime resolution for the Address union returned by Query.resolve_address. Done means the query completes without the abstract-type error and produces the expected L2/L3 data.
Written by the indexing model from the issue text.
Description
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.
- Dominant language
- Python
- Stars
- 371
- Forks
- 175
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from graphql-python/graphql-core-legacy
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
Quiver source Open
Difficulty 5/5 Over a week Newbie friendliness 20/100
graphql-python/graphql-core-legacy#286 · 3 reactions ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
-
Difficulty 3/5 1-2 days Newbie friendliness 35/100
graphql-python/graphql-core-legacy#280 · 2 comments · 1 reaction ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
All issues in graphql-python/graphql-core-legacy
Similar issues
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
xinnan-tech/xiaozhi-fde-talk#263 ·
-
rules
Difficulty 1/5 Under an hour Newbie friendliness 90/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
huggingface/Repo2RLEnv#163 · 1 comment ·
-
Difficulty 1/5 Under an hour Newbie friendliness 95/100
huggingface/sentence-transformers#4074 ·
-
comp/dashboard invalid P3
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
NousResearch/hermes-agent#121143 ·