8000 Fragment Operation with inline and nested fragments "Unknown fragments..." error · Issue #211 · profusion/sgqlc · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Fragment Operation with inline and nested fragments "Unknown fragments..." error #211
Open
@aychang95

Description

@aychang95

First of all, I just want to thank the maintainers of sgqlc for making such a great and useful library like sgqlc. It works very well out of the box and provides creative convenience with the codegen tool!

We're relying on sgqlc heavily as a dependency in our new python SDK for Golden's Knowledge Graph Protocol here https://github.com/goldenrecursion/godel

So we've been running into an issue with our fragments not working correctly with the Operations generated by codegen.

Background

We have directories containing *.graphql files in fragments/ and queries/. Each file contains a single query/fragment.
We run codegen to create a python module for each file.
Queries import fragments and some fragments import other fragments as well.

Problem

We have a fragment that defined as:

fragment TripleWidget on Triple {
  ... on Statement {
    <nested fragments>
  }

The Operation generated from this fragment with codegen doesn't seem to work in general and/or with nested fragments:

from godel.fragments.EntityLink import fragment_entity_link
import sgqlc.types
import sgqlc.operation
import godel.schema

_schema = godel.schema
_schema_root = _schema.schema

__all__ = ('Operations',)


def fragment_triple_widget():
    _frag = sgqlc.operation.Fragment(_schema.Triple, 'TripleWidget')
    _frag__as__Statement = _frag.__as__(_schema.Statement)
    _frag__as__Statement.id()
    _frag__as__Statement.date_accepted()
    _frag__as__Statement.date_rejected()
    _frag__as__Statement.user_id()
    _frag__as__Statement.validation_status()
    _frag__as__Statement_subject = _frag__as__Statement.subject()
    _frag__as__Statement_subject.__fragment__(fragment_entity_link())
    _frag__as__Statement_predicate = _frag__as__Statement.predicate()
    _frag__as__Statement_predicate.id()
    _frag__as__Statement_predicate.name()
    _frag__as__Statement_predicate.description()
    _frag__as__Statement_predicate.label()
    _frag__as__Statement_predicate.object_type()
    _frag__as__Statement_predicate.show_in_infobox()
    _frag__as__Statement.object_value()
    _frag__as__Statement_object_entity = _frag__as__Statement.object_entity()
    _frag__as__Statement_object_entity.__fragment__(fragment_entity_link())
    _frag__as__Statement_citations_by_triple_id = _frag__as__Statement.citations_by_triple_id()
    _frag__as__Statement_citations_by_triple_id_nodes = _frag__as__Statement_citations_by_triple_id.nodes()
    _frag__as__Statement_citations_by_triple_id_nodes.url()
    _frag__as__Statement_qualifiers_by_subject_id = _frag__as__Statement.qualifiers_by_subject_id()
    _frag__as__Statement_qualifiers_by_subject_id_nodes = _frag__as__Statement_qualifiers_by_subject_id.nodes()
    _frag__as__Statement_qualifiers_by_subject_id_nodes.id()
    _frag__as__Statement_qualifiers_by_subject_id_nodes_predicate = _frag__as__Statement_qualifiers_by_subject_id_nodes.predicate()
    _frag__as__Statement_qualifiers_by_subject_id_nodes_predicate.name()
    _frag__as__Statement_qualifiers_by_subject_id_nodes.object_value()
    return _frag


class Fragment:
    triple_widget = fragment_triple_widget()


class Operations:
    fragment = Fragment

When running a query that uses this fragment, we get the error

{'errors': [{'message': 'Unknown fragment "EntityDetail".', ...
# and/or
{'message': 'Unknown fragment "TripleWidget".', ...

Digging into the generated operations, I noticed that the Operation objects don't seem to have the fragments included even though they should have been added through lines like _frag__as__Statement_subject.__fragment__(fragment_entity_link())

Does anyone know what seems to be going on here?

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    0