Skip to content

Commit 19bf9b3

Browse files
authored
Update UPGRADE-v2.0.md
1 parent 1e20e2b commit 19bf9b3

File tree

1 file changed

+7
-52
lines changed

1 file changed

+7
-52
lines changed

UPGRADE-v2.0.md

Lines changed: 7 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -25,42 +25,6 @@ developer has to write to use them.
2525
2626
## Deprecations
2727

28-
### Simpler resolvers
29-
30-
All the resolvers in graphene have been simplified.
31-
Prior to Graphene `2.0`, all resolvers required four arguments: `(root, args, context, info)`.
32-
Now, resolver `args` are passed as keyword arguments to the function, and `context` argument dissapeared in favor of `info.context`.
33-
34-
Before:
35-
36-
```python
37-
my_field = graphene.String(my_arg=graphene.String())
38-
39-
def resolve_my_field(self, args, context, info):
40-
my_arg = args.get('my_arg')
41-
return ...
42-
```
43-
44-
With 2.0:
45-
46-
```python
47-
my_field = graphene.String(my_arg=graphene.String())
48-
49-
def resolve_my_field(self, info, my_arg):
50-
return ...
51-
```
52-
53-
And, if you need the context in the resolver, you can use `info.context`:
54-
55-
```python
56-
my_field = graphene.String(my_arg=graphene.String())
57-
58-
def resolve_my_field(self, info, my_arg):
59-
context = info.context
60-
return ...
61-
```
62-
63-
6428
### AbstractType deprecated
6529

6630
AbstractType is deprecated in graphene 2.0, you can now use normal inheritance instead.
@@ -135,9 +99,9 @@ class User(Mutation):
13599

136100
### Simpler resolvers
137101

138-
All the resolvers in graphene have been simplified. If before resolvers required
139-
four arguments `root`, `args`, `context` and `info`, now the `args` are passed as keyword arguments
140-
and `context` and `info` will only be passed if the function is annotated with it.
102+
All the resolvers in graphene have been simplified.
103+
Prior to Graphene `2.0`, all resolvers required four arguments: `(root, args, context, info)`.
104+
Now, resolver `args` are passed as keyword arguments to the function, and `context` argument dissapeared in favor of `info.context`.
141105

142106
Before:
143107

@@ -154,26 +118,17 @@ With 2.0:
154118
```python
155119
my_field = graphene.String(my_arg=graphene.String())
156120

157-
def resolve_my_field(self, my_arg):
158-
return ...
159-
```
160-
161-
And, if the resolver want to receive the context:
162-
163-
```python
164-
my_field = graphene.String(my_arg=graphene.String())
165-
166-
def resolve_my_field(self, context: graphene.Context, my_arg):
121+
def resolve_my_field(self, info, my_arg):
167122
return ...
168123
```
169124

170-
which is equivalent in Python 2 to:
125+
And, if you need the context in the resolver, you can use `info.context`:
171126

172127
```python
173128
my_field = graphene.String(my_arg=graphene.String())
174129

175-
@annotate(context=graphene.Context)
176-
def resolve_my_field(self, context, my_arg):
130+
def resolve_my_field(self, info, my_arg):
131+
context = info.context
177132
return ...
178133
```
179134

0 commit comments

Comments
 (0)