Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hello world example not working #689

Closed
ahujamoh opened this issue Mar 19, 2018 · 5 comments
Closed

Hello world example not working #689

ahujamoh opened this issue Mar 19, 2018 · 5 comments

Comments

@ahujamoh
Copy link

Dear Contributors,

I was trying the graphql example given on the website: https://graphql.org/code/#python

I copied the code exactly.

import graphene
class Query(graphene.ObjectType):
  hello = graphene.String()

  def resolve_hello(self, args, context, info):
    return 'Hello world!'

schema = graphene.Schema(query=Query)
result = schema.execute('{ hello }')
print(result.data['hello'])

Also having installed graphene using pip(angular is name of my virtualenv)

> pip install graphene
Requirement already satisfied: graphene in /Users/mohit/virtualenvs/angular/lib/python2.7/site-packages
Requirement already satisfied: six<2,>=1.10.0 in /Users/mohit/virtualenvs/angular/lib/python2.7/site-packages (from graphene)
Requirement already satisfied: graphql-core<3,>=2.0 in /Users/mohit/virtualenvs/angular/lib/python2.7/site-packages (from graphene)
Requirement already satisfied: promise<3,>=2.1 in /Users/mohit/virtualenvs/angular/lib/python2.7/site-packages (from graphene)
Requirement already satisfied: graphql-relay<1,>=0.4.5 in /Users/mohit/virtualenvs/angular/lib/python2.7/site-packages (from graphene)
Requirement already satisfied: rx>=1.6.0 in /Users/mohit/virtualenvs/angular/lib/python2.7/site-packages (from graphql-core<3,>=2.0->graphene)
Requirement already satisfied: typing in /Users/mohit/virtualenvs/angular/lib/python2.7/site-packages (from promise<3,>=2.1->graphene)
(angular)

I tried running python hello.py, but got the following error.

> python hello.py
No handlers could be found for logger "graphql.execution.executor"
Traceback (most recent call last):
  File "/Users/mohit/virtualenvs/angular/lib/python2.7/site-packages/graphql/execution/executor.py", line 311, in resolve_or_error
    return executor.execute(resolve_fn, source, info, **args)
  File "/Users/mohit/virtualenvs/angular/lib/python2.7/site-packages/graphql/execution/executors/sync.py", line 7, in execute
    return fn(*args, **kwargs)
graphql.error.located_error.GraphQLLocatedError: resolve_hello() takes exactly 4 arguments (2 given)
None

May I know if I got mistaken at some place, or the instructions on the website are incomplete?

Thanks

@patrick91
Copy link
Member

The guide on graphql.org is outdated :)

See http://docs.graphene-python.org/en/latest/quickstart/#creating-a-basic-schema

@ahujamoh
Copy link
Author

ahujamoh commented Mar 19, 2018

The new example works, thanks. Hence, I am closing this issue.

@alexisrolland
Copy link

@ahujamoh, on a slightly different note but in case this would be of interest for you, I have put together a tutorial to use Graphene with SQLAlchemy and Flask. Feel free to check it out here: https://github.com/alexisrolland/flask-graphene-sqlalchemy/wiki

@jkimbo
Copy link
Member

jkimbo commented Mar 19, 2018

@ahujamoh I'm sure they would appreciate a PR to update their documentation

@ahujamoh
Copy link
Author

@jkimbo thanks for the idea, raised the PR 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants