Comments (5)
This seems fixable as we currently perform reparsing of enums based on the simple info.returnType of a field without checking for unions. Lists should work, though. Can you check?
You could maybe move the pace of a fix along just by including more of your test case code? Or submitting a PR for handling unions similar to how lists are handled.
I do not think this should be any different whether you are using fragments or not. Can you check that, too?
Thanks for submitting!
from graphql-tools-fork.
Here's a snippet with a minimalistic reproduction:
import { ApolloServer } from "apollo-server-express";
import { createTestClient } from "apollo-server-testing";
import { GraphQLSchema } from "graphql";
import { GraphQLResponse } from "graphql-extensions";
import { FilterRootFields, transformSchema } from "graphql-tools-fork";
import { buildSchemaSync, createUnionType, Field, ObjectType, Query, registerEnumType, Resolver } from "type-graphql";
function createTestSchema(): GraphQLSchema {
enum TestEnum {
One = "bug",
Two = "issue"
}
registerEnumType(TestEnum, {
name: "TestEnum"
});
@ObjectType()
class TestObject {
@Field(_type => TestEnum)
public type: TestEnum = TestEnum.One;
}
@ObjectType()
class SecondTestObject {
@Field(_type => TestEnum)
public type: TestEnum = TestEnum.Two;
@Field(_type => [TestEnum])
public typeArray: TestEnum[] = [TestEnum.One, TestEnum.Two]
}
const testUnionType = createUnionType({
name: "TestUnionType",
types: [TestObject, SecondTestObject]
});
@Resolver(_of => TestObject)
class TestResolver {
@Query(_type => testUnionType)
public getUnion(): TestObject | SecondTestObject {
return new SecondTestObject();
}
}
return buildSchemaSync({
resolvers: [TestResolver]
});
}
function execute(schema: GraphQLSchema, query: string): Promise<GraphQLResponse> {
const server = new ApolloServer({ schema });
return createTestClient(server).query({ query });
}
const schema = createTestSchema();
const transformedSchema = transformSchema(schema, [
new FilterRootFields((_operation, _fieldName, _field) => true)
]);
it("preserves enum on fragment when schema is transformed", async () => {
const query = "query { getUnion { ... on SecondTestObject { type } } }";
const response = await execute(schema, query);
const transformedResponse = await execute(transformedSchema, query);
expect(response).toEqual(transformedResponse);
expect(transformedResponse).toEqual({
data: {
getUnion: {
type: "Two"
}
}
})
});
it("preserves enum array on fragment when schema is transformed", async () => {
const query = "query { getUnion { ... on SecondTestObject { typeArray } } }";
const response = await execute(schema, query);
const transformedResponse = await execute(transformedSchema, query);
expect(response).toEqual(transformedResponse);
expect(transformedResponse).toEqual({
data: {
getUnion: {
type: ["One", "Two"]
}
}
})
});
Covers both enum and enum array for union type.
It works fine when it's not a union.
from graphql-tools-fork.
Looks like we should add another case here:
Pseudocode: (isUnionType(type) && type.resolveType(value) === (GraphqlEnumType || GraphqlScalarType))
Do you want to give that a try in PR?
from graphql-tools-fork.
I actually misunderstood your bug, I thought it was of unions of enums, not unions of object types with enum fields. (And it turns out you cannot even have union of scalar types, only that of object types!)
The problem in this case was therefore not in the parseOutputValue logic, but rather that defaultMergedResolver was not getting called for unions (and probably interfaces!)
That should now be fixed. Here's hoping.
from graphql-tools-fork.
Sorry for the confusion, I thought that the snippet made it clear.
It's fixed now, thank you!
from graphql-tools-fork.
Related Issues (20)
- TransformRootFields + RenameObjectFields not working together HOT 9
- Multiple errors not merged correctly HOT 7
- Errors are getting lost for array elements HOT 10
- Error when handling resolver error HOT 7
- Stitched schema errors are replaced with another one HOT 9
- Test with graphql-js v15.0.0-rc.1 HOT 3
- Did not fetch typename for object, unable to resolve interface HOT 32
- Overriding remote custom scalars/enums not working when renaming types HOT 1
- delegateToSchema return type HOT 2
- Prevent sync operations from becoming async
- Transforms can lead to "empty" types breaking schema HOT 14
- applySchemaTransforms not called in delegateToSchema HOT 6
- Test with graphql-js v15.0.0-rc.2 HOT 11
- Requiring apollo-link-http-common enforces dom to the tsconfig libs HOT 8
- Question: ApolloLink for remote schemas with cache? HOT 8
- RenameTypes + RenameObjectFields with interface resolveType not transforming correctly HOT 4
- Question: Schema Transform partial application of arguments HOT 10
- Improve typedoc documentation coverage.
- Schema delegation doesn't work with query variables in nested fields HOT 2
- Unable to mutate enum value through visitEnumValue HOT 2
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-tools-fork.