Cannot query field "_service" on type "Query". I'm not using Federation. #6238
-
So I have a GraphQL server built with apollo-server and recently I started to get this error. As far as I am aware I did not get this error before and I didn't make any changes to the schema that would create this error, I only added new functionality (new definitions) to the schema. backend | [1647789666605] ERROR (35 on 67ad11a8ae06): Cannot query field "_service" on type "Query".
backend | err: {
backend | "type": "ValidationError",
backend | "message": "Cannot query field \"_service\" on type \"Query\".",
backend | "locations": [
backend | {
backend | "line": 2,
backend | "column": 9
backend | }
backend | ],
backend | "extensions": {
backend | "code": "GRAPHQL_VALIDATION_FAILED",
backend | "exception": {
backend | "stacktrace": [
backend | "GraphQLError: Cannot query field \"_service\" on type \"Query\".",
backend | " at Object.Field (/node_modules/graphql/validation/rules/FieldsOnCorrectTypeRule.js:48:31)",
backend | " at Object.enter (/node_modules/graphql/language/visitor.js:323:29)",
backend | " at Object.enter (/node_modules/graphql/utilities/TypeInfo.js:370:25)",
backend | " at visit (/node_modules/graphql/language/visitor.js:243:26)",
backend | " at validate (/node_modules/graphql/validation/validate.js:69:24)",
backend | " at validate (/node_modules/apollo-server-core/src/requestPipeline.ts:470:27)",
backend | " at processGraphQLRequest (/node_modules/apollo-server-core/src/requestPipeline.ts:261:30)",
backend | " at processTicksAndRejections (node:internal/process/task_queues:96:5)",
backend | " at async processHTTPRequest (/node_modules/apollo-server-core/src/runHttpQuery.ts:346:24)"
backend | ]
backend | }
backend | }
backend | } A few things about this issue:
My Apollo Server config is as follows (I am using const apolloServer = new ApolloServer({
schema: makeExecutableSchema({
typeDefs,
resolvers,
resolverValidationOptions: {
requireResolversForResolveType: 'ignore',
},
}),
introspection: true,
playground: isDev,
tracing: isDev,
// Context is passed down to every resolver
async context({ req }): Promise<AppContext> {
const requestOwnerId = req.headers['authenticated-user'] as string;
return { prisma, requestOwnerId };
},
formatError: errorFormatter, // error formatting function
plugins: [
ApolloServerPluginDrainHttpServer({ httpServer }),
],
} as Config<ExpressContext>); Every single instance of this error I found online mention federation, and I am confused as I am not using a federated schema whatsoever. What am I doing wrong? In Apollo Studio I can confirm I have a single schema, and not subgraphs. Thanks a lot. |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 8 replies
-
@vmarchesin Did you by any chance start using Apollo Studio recently? It seems the error is caused by Apollo Studio polling your schema. |
Beta Was this translation helpful? Give feedback.
-
@haykerman I've been using Apollo Studio since I started with this project. I did not get any errors until recently, and I have no idea what could cause this besides what is in the federation docs. I just stripped my typedefs and resolvers to be as barebones as possible, and I just have the typedef and resolver for: // resolver
export default {
Node: {
__resolveType: (obj) => obj,
},
}; # typedef
scalar Cursor
scalar JSON
scalar JSONObject
interface Node {
id: ID!
}
type Records {
count: Int
}
type PageInfo {
startCursor: String
endCursor: String
}
type Query {
node(id: ID!): Node
}
input PaginationInput {
skip: Int
take: Int
cursor: Cursor
}
input FilterInput {
orderBy: String
sortOrder: JSON
} Of course none of the queries work because I removed all the other stuff from the project, but just with this the server is able to start successfully and I still get the same error when loading Apollo Studio. I'm using // typeDefs/index.js
import { join } from 'path';
import { loadFilesSync } from '@graphql-tools/load-files';
import { mergeTypeDefs } from '@graphql-tools/merge';
import { DocumentNode } from 'graphql';
const typesArray = loadFilesSync(join(__dirname, '.'), { extensions: ['graphql'] });
export default mergeTypeDefs(typesArray) as DocumentNode;
// resolvers/index.js
import { mergeResolvers } from '@graphql-tools/merge';
import Common from './common';
import MoreResolvers from './otherResolverFiles';
// ... more resolver imports here
import AppContext from 'server/types/appContext';
export default mergeResolvers<any, AppContext>([
Common,
MoreResolvers,
// ... more resolvers here
]); These are imported as const apolloServer = new ApolloServer({
schema: makeExecutableSchema({
typeDefs,
resolvers,
resolverValidationOptions: {
requireResolversForResolveType: 'ignore',
},
}),
... So no schema stitching, no federation. It does seem like an Apollo Studio issue because I do not get the |
Beta Was this translation helpful? Give feedback.
-
I should mention that I am using the following dependencies (all updated to the latest available version): "dependencies": {
"@graphql-tools/load-files": "^6.5.3",
"@graphql-tools/merge": "^8.2.4",
"@graphql-tools/schema": "^8.3.3",
"@prisma/client": "^3.11.0",
"apollo-server-core": "^3.6.4",
"apollo-server-errors": "^3.3.1",
"apollo-server-express": "^3.6.4",
"body-parser": "^1.19.2",
"dotenv": "^16.0.0",
"express": "^4.17.3",
"graphql": "^16.3.0",
"graphql-type-json": "^0.3.2",
"pino": "^7.9.1",
"pino-pretty": "^7.5.4"
}, |
Beta Was this translation helpful? Give feedback.
-
By any chance have there been any recent changes to Apollo Studio that may have reintroduced the Same as above, this is only a problem when fetching the schema during development. I've looked into other clients for fetching the schema (e.g. Altair GraphQL Client) and the same issue is not present. |
Beta Was this translation helpful? Give feedback.
-
Hello, a fix should have gone out for this a couple days ago. Let me know if you see this as a continued issue. Thanks for the report! |
Beta Was this translation helpful? Give feedback.
@haykerman I've been using Apollo Studio since I started with this project. I did not get any errors until recently, and I have no idea what could cause this besides what is in the federation docs. I just stripped my typedefs and resolvers to be as barebones as possible, and I just have the typedef and resolver for: