-
-
Notifications
You must be signed in to change notification settings - Fork 809
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
[utils] fix broken sofa-api schema #1928
Conversation
I got a bug while using the new version of sofa-api. Not nullable fields for some reason got unexpected suffix like `status` -> `statusUserStatusNonNull`. I tracked the issue to @graphql-util/utils and tried to drop the code. My app started working. Tests still passed and there is not comments why this code is necessary.
Maybe I'm as usual do not setup it properly. Could you point me if there is a problem here? const resolvers = {
Query: {
async user(parent, args, context, info) {
return delegateToSchema({
schema,
operation: 'query',
fieldName: 'user',
args,
context,
info,
});
}
}
}
const executableSchema = addResolversToSchema({
schema: loadSchemaSync('./src/schema.graphql', {
loaders: [new GraphQLFileLoader()],
}),
resolvers,
resolverValidationOptions: {
requireResolversForResolveType: false,
},
});
const openApi = OpenAPI({
schema: executableSchema,
});
const sofaRoute = useSofa({
schema: executableSchema,
onRoute(info) {
openApi.addRoute(info, {
basePath: '/api',
});
},
context({ req, res }) {
return new Context({ req, res });
},
async execute({
schema,
source,
contextValue,
variableValues,
operationName,
}) {
return graphql({
schema,
source,
contextValue,
variableValues,
operationName,
})
},
})
app.use(sofaRoute) |
cc @ardatan |
Hi @yaacovCR. Do you have an idea why this renaming happens? |
Unfortunately not! Not too familiar with sofa portion of codebase! |
@TrySound Not sure why it breaks for you because it is added with an alias if field names don't match; As I remember, we added this workaround for the case like I explained below. type Query {
entity(id: ID): Entity
}
union Entity = Book | User | Comment
type Book {
id: ID!
name: String
}
type User {
id: ID
name: String
}
type Comment {
id: ID
name: String
} And this operation(something like this code used to generate before) breaks against this schema;
because types of entity(id: 2){
... on Book {
id
name
}
... on User {
id: idNonNull
name
}
} But it probably causes other bugs so if you share a minimal reproduction repo or CodeSandbox, we can help you better. |
Here's minimal reproduction. The problem is that schema is imported from another one and it's not easy to rename such fields. |
Wow, preview works! Thanks! |
Fixed in 6.1.0 in @graphql-tools/utils and this package has been updated in sofa 0.8.1 |
@ardatan I don't see release in github. Did you forget to push it? |
graphql-tools is released very often. Though sofa-api does not reflect all those releases and my project end with duplicated graphql-tools dependencies. Maybe it's worth to add ^ or at least ~ in version range? |
It only uses one specific function from utils so I think using an exact version would keep it more stable |
Still not release on github. You'll get conflict when renovate will merge another pull request. |
I got a bug while using the new version of sofa-api.
Not nullable fields for some reason got unexpected suffix like
status
->statusUserStatusNonNull
. And the app crashedbecause non null field resolved to not existing one.
I tracked the issue to @graphql-tools/utils and tried to drop the code.
My app started working. Tests still passed and there is not comments
why this code is necessary.
TODO: