Created
January 24, 2025 14:16
-
-
Save mac2000/510f1d26e9dd562a44a201983d914578 to your computer and use it in GitHub Desktop.
oneoff
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"errors": [ | |
{ | |
"message": "Cannot query field \"isOneOf\" on type \"__Type\".", | |
"extensions": { | |
"code": "INVALID_GRAPHQL", | |
"stacktrace": [ | |
"GraphQLError: Cannot query field \"isOneOf\" on type \"__Type\".", | |
" at Object.err (/Users/mac/Desktop/oneoff/supergraph/node_modules/@apollo/federation-internals/dist/error.js:11:32)", | |
" at validate (/Users/mac/Desktop/oneoff/supergraph/node_modules/@apollo/federation-internals/dist/operations.js:15:46)", | |
" at selectionOfNode (/Users/mac/Desktop/oneoff/supergraph/node_modules/@apollo/federation-internals/dist/operations.js:2386:13)", | |
" at selectionSetOfNode (/Users/mac/Desktop/oneoff/supergraph/node_modules/@apollo/federation-internals/dist/operations.js:2366:24)", | |
" at selectionOfNode (/Users/mac/Desktop/oneoff/supergraph/node_modules/@apollo/federation-internals/dist/operations.js:2389:19)", | |
" at selectionSetOfNode (/Users/mac/Desktop/oneoff/supergraph/node_modules/@apollo/federation-internals/dist/operations.js:2362:43)", | |
" at parseSelectionSet (/Users/mac/Desktop/oneoff/supergraph/node_modules/@apollo/federation-internals/dist/operations.js:2472:26)", | |
" at operationFromAST (/Users/mac/Desktop/oneoff/supergraph/node_modules/@apollo/federation-internals/dist/operations.js:2456:55)", | |
" at operationFromDocument (/Users/mac/Desktop/oneoff/supergraph/node_modules/@apollo/federation-internals/dist/operations.js:2448:12)", | |
" at /Users/mac/Desktop/oneoff/supergraph/node_modules/@apollo/gateway/dist/index.js:78:100" | |
] | |
} | |
} | |
] | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { ApolloServer } from '@apollo/server' | |
import { startStandaloneServer } from '@apollo/server/standalone' | |
import { parse } from 'graphql' | |
import { buildSubgraphSchema } from '@apollo/subgraph' // added for federation | |
const typeDefs = parse(`#graphql | |
directive @oneOf on INPUT_OBJECT | |
type Query { | |
users(where: UserWhere!): [User!]! | |
} | |
type User { | |
id: ID! | |
username: String | |
} | |
input UserWhere @oneOf { | |
foo: Int | |
bar: Int | |
} | |
`) | |
const resolvers = { | |
Query: { | |
users: () => [{ id: '1', username: '@mac' }], | |
}, | |
} | |
const server = new ApolloServer({ | |
schema: buildSubgraphSchema({ typeDefs, resolvers }), // federated graphql server, instead of `typeDefs, resolvers` | |
}) | |
startStandaloneServer(server).then(({ url }) => console.log(`open ${url}`)) | |
/* | |
# should return UserWhere type with isOneOf true | |
{ | |
__type(name: "UserWhere") { | |
name | |
isOneOf | |
} | |
} | |
# as well as sdl, which also has UserWhere type marked with @oneOf | |
{ | |
_service { sdl } | |
} | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { ApolloServer } from '@apollo/server' | |
import { ApolloGateway, IntrospectAndCompose } from '@apollo/gateway' | |
import { startStandaloneServer } from '@apollo/server/standalone' | |
const gateway = new ApolloGateway({ | |
supergraphSdl: new IntrospectAndCompose({ | |
subgraphs: [{ name: 'demo', url: 'http://localhost:4000' }], | |
}), | |
}) | |
const server = new ApolloServer({ gateway }) | |
startStandaloneServer(server, { listen: { port: 3000 } }).then(({ url }) => console.log(`open ${url}`)) | |
/* | |
# Cannot query field "isOneOf" on type "__Type" 🤷♂️ | |
{ | |
__type(name: "UserWhere") { | |
name | |
isOneOf | |
} | |
} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment