Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

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

Open
#106 0 comments 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
25/100
Issue type
Bug
Clarity
Needs clarification
Activity status
Stale
Tech stack
python
Domain
api

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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from graphql-python/graphql-core-legacy

All issues in graphql-python/graphql-core-legacy

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.