Open grvhi opened 5 years ago
Hi, could you please give me a complete sample for reproducing? I do not know the definition of CommandRegister
.
@ethe - I've updated my original comment with the necessary representation being passed into the command field
I am sorry that I can not reproduce the issue following your sample. Please make sure that you have already used the newest version of Pygraphy.
Here is my test file according to your discription.
import asyncio
from typing import Optional, List
from pygraphy import Object, Query as BaseQuery, field, Schema as BaseSchema
class CommandResponseAttributes(Object):
field_type: str
required: bool
description: Optional[str]
class CommandResponseObject(Object):
field_name: str
attributes: CommandResponseAttributes
class CommandObject(Object):
command_name: str
description: Optional[str]
response_schema: List[CommandResponseObject]
def response_schema() -> dict:
return {
'new_handle': {
'field_type': 'string',
'required': True,
'description': 'The handle just created, without @<domain>'
},
'send_to': {
'field_type': 'string',
'required': True,
'description': 'The actual email address to which this handle '
'will forward accepted emails.'
},
'accept_email': {
'field_type': 'string',
'required': False,
'description': 'The only email address from which emails will '
'be accepted by this handle. If `None`, the '
'handle\'s other incoming rules apply.'
},
'accept_domain': {
'field_type': 'string',
'required': False,
'description': 'The only email domain from which emails will '
'be accepted by this handle. If `None`, the '
'handle\'s other incoming rules apply.'
},
'lock_email': {
'field_type': 'boolean',
'required': True,
'description': 'Will this handle be locked to the email '
'of the sender of the first email received by '
'this handle?'
},
'lock_domain': {
'field_type': 'boolean',
'required': True,
'description': 'Will this handle be locked to the domain '
'of the sender of the first email received by '
'this handle?'
},
'source_domain': {
'field_type': 'string',
'required': False,
'description': 'The domain of the website for which this '
'handle was created, if available.'
}
}
class Query(BaseQuery):
@field
def command(self, command_name: str) -> CommandObject:
schema = list()
for field_name, attributes in response_schema().items():
# noinspection PyArgumentList
schema.append(
CommandResponseObject(
field_name=field_name,
attributes=CommandResponseAttributes(**attributes)
)
)
data = {
'command_name': 'test',
'description': None,
'response_schema': schema
}
# noinspection PyArgumentList
return CommandObject(**data)
class Schema(BaseSchema):
query: Optional[Query]
print(asyncio.run(Schema.execute('''
{
command(commandName: "test") {
responseSchema {
fieldName
attributes {
description
required
fieldType
}
}
}
}
''')))
Thanks @ethe - I see my problem was with the query I was submitting. The simplified version of the query I was using is:
{command(commandName: "test") {responseSchema}}
If you run this query, you should get the same exception messages as I did above. While the error is in the query, I think Pygraphy
could/should return a more helpful error message?
The issue seems to be specifically the omission of sub-selections in the query.
I think maybe {command(commandName: "test") {responseSchema}}
is not a valid GraphQL query, as GraphQL Spec, you should describe each field you want explicitly, could you please provide more info about it?
I think maybe
{command(commandName: "test") {responseSchema}}
is not a valid GraphQL query, as GraphQL Spec, you should describe each field you want explicitly, could you please provide more info about it?
Yes, you're absolutely correct: my suggestion is that Pygraphy
should require sub-selections when querying for an object.
If I'm not mistaken, in the same situation graphene
returns an error stating that responseSchema
requires sub-fields to be selected as part of the query. i.e. In validating the query, graphene
detects that no fields under responseSchema
have been selected and immediately raises an exception.
You are right, the Pygraphy should return more helpful messages after an error query. I will fix it recently, than you!
You are right, the Pygraphy should return more helpful messages after an error query. I will fix it recently, than you!
Thank you! It's great to be finally working with a pythonic GraphQL library!
Thank you!
I'm trying to add support for nested objects in my graph per the example below. But it seems that the nested objects are not parsed/read correctly?
With the following Query:
But sending a query for these objects results in the following exception: