feat: schema provider and operation session context using context/useReducer#1359
feat: schema provider and operation session context using context/useReducer#1359
Conversation
|
@zephraph going to break some of these interfaces, since this PR breaks GraphiQL.state we might as well get rid of the GraphiQL.Logo pattern as well. See: pinned issue |
|
This is mostly ready, aside from some some cleanup. Last step, was thinking of bringing schema context into DocExplorer using just render props, since it doesn't seem to be re-rendering from the top via |
6b3e9af to
20ed39a
Compare
* Initial migration context wrapper * Pull out other static properties * Fix refs bug by properly accessing current
336c32c to
a174c58
Compare
Co-Authored-By: Justin Bennett <[email protected]>
|
@AlecAivazis welcome back! :) did you add yourself as a reviewer? |
31fc6e0 to
246c51e
Compare
Codecov Report
@@ Coverage Diff @@
## master #1359 +/- ##
===========================================
- Coverage 58.96% 36.92% -22.05%
===========================================
Files 60 64 +4
Lines 3022 2941 -81
Branches 796 731 -65
===========================================
- Hits 1782 1086 -696
- Misses 1194 1833 +639
+ Partials 46 22 -24
Continue to review full report at Codecov.
|
| ? 'http://localhost:8080/graphql' | ||
| : 'https://swapi-graphql.netlify.com/.netlify/functions/index'; | ||
|
|
||
| export const initialReducerState: SchemaState = { |
There was a problem hiding this comment.
Is it possible to use discriminated unions so invalid states are impossible to represent?
A simplified example (Reason syntax since it's terser, but I think TS can represent this):
type schemaState =
| Loading
| Error(string)
| Loaded(schema)
There was a problem hiding this comment.
this is just temporary for the demo, but yes it is, via typescript. that would come in a later PR
There was a problem hiding this comment.
lets talk about state in the plugin spec
cshaver
left a comment
There was a problem hiding this comment.
I haven't looked at this too closely yet, but I noticed one small thing where fetch is used:
| query: introspectionQuery, | ||
| operationName: introspectionQueryName, | ||
| }), | ||
| headers: { 'Content-Type': 'application/json', credentials: 'omit' }, |
There was a problem hiding this comment.
| headers: { 'Content-Type': 'application/json', credentials: 'omit' }, | |
| headers: { 'Content-Type': 'application/json' }, | |
| credentials: 'omit', |
| const rawResult = await fetch(schemaConfig.uri, { | ||
| method: 'post', | ||
| body: JSON.stringify(graphqlParams), | ||
| headers: { 'Content-Type': 'application/json', credentials: 'omit' }, |
There was a problem hiding this comment.
| headers: { 'Content-Type': 'application/json', credentials: 'omit' }, | |
| headers: { 'Content-Type': 'application/json' }, | |
| credentials: 'omit', |
|
@cshaver if you notice anything funky with tests, its because they're disabled temporarily for the RFC puproses @ryan-m-walker is also around to help, he helped me start this PR! |
| {options} | ||
| </div> | ||
| export function ExecuteButton(props: ExecuteButtonProps) { | ||
| const [optionsOpen, setOptionsOpen] = useState<boolean>(false); |
There was a problem hiding this comment.
the generic isn't needed here. the type can be inferred
| payload: { value: variablesText, sessionId }, | ||
| }); | ||
| const executeOperation = async ( | ||
| sessionState: SessionState, |
There was a problem hiding this comment.
it feels kind of strange that you have to pass the session state back into this function. Shouldn't the outer scope provide everything this function needs or are you trying to just encapsulate it all? lines like this one just feel strange to me:
| null, | ||
| ); | ||
| const session = useSessionContext(); | ||
| const operations = props.operations ?? []; |
There was a problem hiding this comment.
should we be getting operations from the session state now instead of props?
… an enum and discriminated union
* made errors consitent across providers * allowed for multiple errors * preserved error objects to allow more custom usage
* eslint-plugin-react-hooks * Move query facts out of session state * Rename sessionReducer
* used the return type of the action creators for the action types
|
closing for #1468, in favor of using a fork for access management purposes. |
please take this and run with it tomorrow however you see fit!
it introduces:
useReducerswhich is meant to expose interfaces (to plugins eventually down the line, but for now we will supply them as props via the provider). glad to field suggestions on how to re-architect this!useReducerrelated utilities inspired from previous redux workflowsSchemaProvider,SchemaContext, etc. feel free to combine this provider into a migration provider like you were discussing earlier @zephraphtypescript types are not happy yet because I'm still wrapping my head around typescript + redux style patterns
note:
some features are temporarily disabled by this effort in the interest of further iterations before we release another alpha: