-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Return an interface with multiple weak concrete types from a resolver…
… field Reviewed By: captbaritone Differential Revision: D56438692 fbshipit-source-id: 12a4a029004f0b17cc71f6919f19597a63824afe
- Loading branch information
1 parent
46879b4
commit 55b8716
Showing
6 changed files
with
476 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
222 changes: 222 additions & 0 deletions
222
...ct-relay/__tests__/__generated__/RelayResolverInterfaceTestWeakAnimalLegsQuery.graphql.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
54 changes: 54 additions & 0 deletions
54
packages/relay-runtime/store/__tests__/resolvers/WeakAnimalQueryResolvers.js
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @format | ||
* @flow strict-local | ||
* @oncall relay | ||
*/ | ||
|
||
import type {Query__weak_animal$normalization} from 'relay-runtime/store/__tests__/resolvers/__generated__/Query__weak_animal$normalization.graphql'; | ||
|
||
/** | ||
* Returns a single `IWeakAnimal` of a given type. | ||
* | ||
* @RelayResolver Query.weak_animal(request: WeakAnimalRequest!): IWeakAnimal | ||
*/ | ||
function weak_animal(args: { | ||
request: {ofType: string}, | ||
}): Query__weak_animal$normalization { | ||
switch (args.request.ofType) { | ||
case 'Octopus': | ||
return { | ||
__relay_model_instance: {}, | ||
__typename: 'Octopus', | ||
}; | ||
case 'PurpleOctopus': | ||
return { | ||
__relay_model_instance: {}, | ||
__typename: 'PurpleOctopus', | ||
}; | ||
default: | ||
throw new Error('Invalid type'); | ||
} | ||
} | ||
|
||
/** | ||
* Returns a list of `IWeakAnimal` of a given type. | ||
* | ||
* @RelayResolver Query.weak_animals(requests: [WeakAnimalRequest!]!): [IWeakAnimal] | ||
*/ | ||
function weak_animals(args: { | ||
requests: $ReadOnlyArray<{ofType: string}>, | ||
}): Array<Query__weak_animal$normalization> { | ||
return args.requests.map(request => { | ||
return weak_animal({request}); | ||
}); | ||
} | ||
|
||
module.exports = { | ||
weak_animal, | ||
weak_animals, | ||
}; |
Oops, something went wrong.