-
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
list.map is not a function #5
Comments
Got it, to reproduce you gonna need update graphql-tools package to latest v5, then you gonna need to change your e.g. transform-federation.spec.ts import { makeExecutableSchema, transformSchema, delegateToSchema } from 'graphql-tools';
import { transformSchemaFederation } from './transform-federation';
import { execute } from 'graphql/execution/execute';
import { DirectiveNode, parse, print, visit } from 'graphql/language';
import dedent = require('dedent');
describe('Transform Federation', () => {
// it('should add a _service field'
it('should resolve references', async () => {
const executableSchema = makeExecutableSchema({
typeDefs: `
type Product {
id: ID!
name: String!
}
type Query {
productById(id: String!): Product!
}
`,
resolvers: {
Query: {
productById(source, { id }) {
return {id: "1", name: "product1"};
},
}
},
});
const federationSchema = transformSchemaFederation(executableSchema, {
Product: {
keyFields: ['id'],
extend: true,
resolveReference(reference: any, context: { [key: string]: any }, info) {
return delegateToSchema({
schema: info.schema,
operation: 'query',
fieldName: 'productById',
args: {
id: reference.id,
},
context,
info,
});
},
},
});
expect(
await execute({
schema: federationSchema,
document: parse(`
query{
_entities (representations: {
__typename:"Product"
id: "1"
}) {
__typename
...on Product {
id
name
}
}
}
`),
}),
).toEqual({
data: {
_entities: [
{
__typename: 'Product',
id: '1',
name: 'product1',
},
],
},
});
});
// it('should throw and error when adding resolveReference on a scalar'
}); and test result:
|
Hm, seems like I did get into version mismatch between projects and it seems that we will have similar issues for a while until graphql v15 and graphql-tools v5 becomes mainstream |
BTW most of documented transformations are available only in graphql-tools@5, so for example at moment we can not remove fields on type with |
Did you manage to resolve this issue @mac2000 |
Yes and no, oh it was so long time ago, I even do not remember all the details Instead of having separate mesh/transformer/whatever service I just bring code pieces directly in gateway, so at that moment gateway looks something like:
so before starting gateway, the same way he is working we are dretrieving remote schema, applying required transsformations and make it executable - profit but at the very end we have managed how to implement federation in dotnet so at moment everything works out of the box without any of such tricks also I see a PR here from me, seems like project at moment is not alive, hopefully owners are well |
@mac2000 Thanks for the detailed explanation. Project seems to be dead for now :( |
@0xR what are your plans? |
I'm working on some other things right now, I might review a PR with a fix. |
SO been digging around trying to solve this issue myself and happy to say i did find a solution that at least works for me. Problem seems to exist because the query thats being run is coming from the federation part of the system so its setting the return type to [Entity]! as @mac2000 said. I fetched the expected return type from the schema and set it as the return type on the delegateToSchema function and seems to be resolving correctly now!
Not sure how we could put a fix for this in as its probably case by case where its actually required and might just depend on what backend service you're using, but maybe could add something to docs? |
Ahah. Idea in newest version of tools is to either use returnType or a transformResult method within a transform that will convert from single result to array, similar to #5 (comment) |
Yeah I tried transforming the result but ran into the same issues with type validation and fields saying they are non-null. Even after changing the type to allow null fields the results never got merged into the final response. Still not sure what the best way forward is. It would be far easier to just have a federation supported backend haha! |
Not sure how you are handling aliases, maybe that's why? GraphQL Tools has
a visitResult function that might be useful.
Seems like you might as well just use the return Type solution if that is
working.
…On Thu, Jan 7, 2021, 4:10 AM Steven White ***@***.***> wrote:
Yeah I tried transforming the result but ran into the same issues with
type validation and fields saying they are non-null. Even after changing
the type to allow null fields the results never got merged into the final
response.
Still not sure what the best way forward is. It would be far easier to
just have a federation supported backend haha!
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#5 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AA7LAYCC2SZJKOR7GQ5DTL3SYUJYZANCNFSM4MRCS2SA>
.
|
Hmm yeah you're right. If I set |
I think safer than overriding the info object is modifying what you pass info delegateToSchema, either via creating a new modified info to pass or just using the returnType option explicitly to set to correct type or null as you have discovered! |
I have taken
transformed-server.ts
from examples and make js from it, no other changestransformed-server.js
Now if I will try run
node transformed-server.js
and try query following:I will get an "list.map is not a function"
After looking around, underneath main query is for
[Entity]
and delegated results is forProduct
so my first attempt was to add following trasformation as a workaround:it does fix an error with list.map error but introduces new one
Cannot return null for non-nullable field Product.id
what is interesting through is that if you clone repo, put this javascript file into it and replace import with
const { transformSchemaFederation } = require('./src/transform-federation');
and will run it withts-node
everything will worki have checked that I'm using latest available version and there is no commits after
The text was updated successfully, but these errors were encountered: