-
Notifications
You must be signed in to change notification settings - Fork 23
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
Aliases do not work #15
Comments
An alternatively (very hacky) solution is to just strip the aliases out before querying the underlying service with diff --git a/example/transformed-server.ts b/example/transformed-server.ts
index 32d89db..9f0c127 100644
--- a/example/transformed-server.ts
+++ b/example/transformed-server.ts
@@ -1,6 +1,7 @@
import { delegateToSchema, makeExecutableSchema } from 'graphql-tools';
import { ApolloServer } from 'apollo-server';
import { transformSchemaFederation } from '../src/transform-federation';
+import { visit } from 'graphql';
const products = [
{
@@ -54,7 +55,35 @@ const federationSchema = transformSchemaFederation(schemaWithoutFederation, {
id: (reference as ProductKey).id,
},
context,
- info,
+ info: {
+ ...info,
+ fieldNodes: info.fieldNodes.map((n) =>
+ visit(n, {
+ Field: (field) => {
+ if (!field.alias) {
+ return undefined;
+ }
+ return {
+ ...field,
+ alias: undefined,
+ };
+ },
+ })
+ ),
+ operation: visit(info.operation, {
+ Field: (field) => {
+ if (!field.alias) {
+ return undefined;
+ }
+ return {
+ ...field,
+ alias: undefined,
+ };
+ },
+ }),
+ },
});
},
}, One thing that I'm not sure of is how this plays with fields with arguments, such as type Name {
name: String!
}
type Product {
id: String!
name(capitalize: Boolean!): Name
}
type Query {
productById(id: String!): Product!
} People write queries such as query {
findProduct {
id
upperCaseName: name(capitalize: true) {
name
}
lowerCaseName: name(capitalize: false) {
name
}
}
} but I don't really understand how that would interplay with this (would the |
For what it's worth I implemented this approach here hasura/graphql-engine#3064 (comment), a lot of the schema/sdl translation was directly inspired by this library, but the query approach is completely different, and avoids the pitfalls of using |
@0xR are there any plans to address this ? wdyt |
Using the example, the following query works
however this query with an alias does not work
I've dug into this a fair amount, and as best as I can tell, this comes because in the course of satisfying this query, the "transformed" data source is queried "twice". The federation server slices up the query and sends the
entity
query to the transformed subgraph(This query has the alias, as one would expect). This query then gets handled by the schema that
transformSchemaFederation
creates. The relevant parts of the query (including aliases) get sent toresolveReference
, which then executes them against the subgraph server. The response fromdelegateToSchema
isThis is where the error arises from, because the query that the federation server made (see above) fulfilled by applying it against the subschema. When the subschema returns with the aliased field names, the query made against it fails since the shape of the data doesn't match the expected shape (missing
name
).I think to do this "right" this library needs to transform the query and data instead of using
deletateToSchema
and effectively "double querying"? But maybe there's an easier fix I'm missing?The text was updated successfully, but these errors were encountered: