I'm investigating using this to progressively replace graphql to generate the schema of a large application. Using types defined with graphql works well by referencing them using their name but I haven't found I way to use types defined with nexus inside a type defined with graphql.
I did try using extendType to extend my types defined using graphql but that doesn't seem to work currently. I'm getting a duplicate type error: Error: Schema must contain unique named types but contains multiple types named "Viewer"..
Here's a simplified example
const Viewer = new GraphQLObjectType({
name: 'Viewer',
fields: {
name: { type: GraphQLString },
},
});
// Using extendType to extend types defined with `graphql`
const NexusViewer = extendType({
type: 'Viewer',
definition(t) {
t.int('age');
},
});
const Query = new GraphQLObjectType({
name: 'Query',
fields: () => ({
viewer: { type: Viewer },
}),
});
const schema = makeSchema({
types: [
Query,
NexusViewer,
],
});
Or alternatively provide a way to convert to a graphql type.
const NexusObjectType = objectType({ name: 'NexusObject' definition() { /* ... */ } });
const GraphQLObjectType = new GraphQLObject({
name: 'GraphQLObject',
fields: { nexus: { type: toGraphQLType(NexusObjectType) } }
});
Yep, this ties into #70 - there needs to be a better story around interop between the two - I'm going to be working more on this in the next few weeks, will comment here once I have something more well defined to test out fo this.
I created an example which shows how graphql types can be used together with nexus: https://codesandbox.io/s/zqq7p9w1jp
In order to do this:
SchemaBuilder and overloadded getOrBuildType```js
getOrBuildType(name, fromObject = false) {
if (isType(name)) {
return this.finalize(name);
}
return super.getOrBuildType(name, fromObject);
}
```
Update: I found that this functionality already built-in :)
Check out #143 and see if this works any better with the newly published 0.12.0-beta.1
@tgriesser If you still remember, can you point to the line in that huge PR?
Hey did this get handled? I'm trying to use graphql-sequelize as it looks like it will save a ton of time.
Really I'm trying to auto-generate models by doing an introspection query on the DB with sequelize, then I want those models to generate the Nexus GraphQL types. This is completely possible and having to write out the DB schema two times is completely redundant.
@blazestudios23 this works
How do i integrate I just get errors, where's what I tried:
t.connectionField(`${TypeNames.name}s_connection`, {
type: TypeNames.name,
resolve: resolver(model.name)
});
I also tried a few variations with:
connectionFromArray
Update, GraphQL-Sequilize is working for a getOne query but doesn't work with:
t.connectionField
Most helpful comment
Yep, this ties into #70 - there needs to be a better story around interop between the two - I'm going to be working more on this in the next few weeks, will comment here once I have something more well defined to test out fo this.