Comments (6)
Looks like the cause (for me at least) was a breaking change in the graphql-binding
API in v2.
This worked with v1.2.5:
binding.mutation.createUser(args, context, info);
but throws a Cannot convert undefined or null to object
error in v2.
I did some digging and it looks like the error is coming from graphql-tools
as it tries to pull fragment definitions from the passed in GraphQLResolveInfo
object. The problem is, the object its trying to pull fragments from is actually the context
object, which has no fragments, and so graphql-tools
throws the error as it tries to iterate over the keys of an undefined object.
Version 2 of graphql-binding
changed the API, and now the context
has to be passed in differently. This is what works now:
binding.mutation.createUser(args, info, { context });
If you upgraded to v2 of graphql-binding
and didn't update your code, you are likely passing in context
in place of info
.
from graphql-binding.
I'm seeing this too.
from graphql-binding.
I should also point out that the generated types for the QueryMap
s on the Binding
class don't agree with the underlying code.
Here are the types:
export declare class Binding extends Delegate {
query: QueryMap;
mutation: QueryMap;
subscription: SubscriptionMap;
constructor({schema, fragmentReplacements, before}: BindingOptions);
buildMethods(): any;
buildQueryMethods(operation: QueryOrMutation): QueryMap;
buildSubscriptionMethods(): SubscriptionMap;
}
// This interface doesn't match the implementation
export interface QueryMap {
[rootField: string]: (args?: {
[key: string]: any;
}, context?: {
[key: string]: any;
}, info?: GraphQLResolveInfo | string) => Promise<any>;
}
And here is the implementation:
Binding.prototype.buildQueryMethods = function (operation) {
var _this = this;
var queryType = operation === 'query'
? this.schema.getQueryType()
: this.schema.getMutationType();
if (!queryType) {
return {};
}
var fields = queryType.getFields();
return Object.entries(fields)
.map(function (_a) {
var fieldName = _a[0], field = _a[1];
return {
key: fieldName,
value: function (args, info, options) { // <-- This implementation doesn't match the QueryMap interface
return _this.delegate(operation, fieldName, args, info, options);
},
};
})
.reduce(function (acc, curr) {
return (__assign({}, acc, (_a = {}, _a[curr.key] = curr.value, _a)));
var _a;
}, {});
};
So even though my code now works, TypeScript is complaining.
from graphql-binding.
We deployed a release today that makes graphql codegen
more robust.
Please install the new cli via npm install -g graphql-cli
and try the graphql codegen
command.
Note that with prisma-binding
1.x, we need to use graphql prepare
and with prisma-binding
2.x, we need to use graphql codegen
Thanks!
from graphql-binding.
binding.mutation.createUser(args, info, { context });
ok this works, thanks 👍
should i close it or let it for the typescript issue?
from graphql-binding.
Thanks everyone involved for the detailed reproductions.
Closing this one as the original issue is resolved. Please open a separate issue in case something is still unresolved. Thanks.
from graphql-binding.
Related Issues (20)
- Support webpack and other bundlers HOT 2
- typescript schema import breaks HOT 6
- Subscriptions are broken on 2.2.2 HOT 1
- Error when calling mutation that is specified inside "extend type Mutation" block HOT 4
- Experiment: using graphql-binding in client-side HOT 5
- Context object not getting sent HOT 2
- Is it possible to use batching? HOT 1
- How to dynamically update the link headers in the binding instance ? HOT 6
- Cannot use Alias with custom binding HOT 2
- [object Object] is returned from a binding when resolver throws an error HOT 14
- method cache and memory leaks HOT 3
- Cannot find module 'graphql/tsutils/Maybe' HOT 5
- mkdirp is not a function HOT 2
- mkdirp race condition HOT 4
- error data from binding is not available HOT 5
- How to write dynamic fragment to use with addFragmentToInfo
- Error with 'fs' and 'module' modules in front end HOT 1
- How can i custom resolves query connection which i expose from "forwardTo" HOT 1
- A new path for graphql-binding - help us decide on the roadmap! HOT 10
- Dependency Dashboard
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from graphql-binding.