-
Notifications
You must be signed in to change notification settings - Fork 5
GraphQL (Construction Process of Mutation)
Naomi Trevino edited this page Sep 20, 2023
·
5 revisions
- Write the mutation query in SQL. This goes in
/types/queries. This particular one updates the document table in the database.
- This gets used in
/src/database_sql.rsas a DataLoader.DocumentMetadataUpdateis a GraphQLInputObjectdefined elsewhere in a rust file (/src/document.rs) and will match with what we give it in the front end.
- This is the
InputObject. All fields under it also need to beInputObjects as well or it will not compile. Here,written_athas a customDateInputtype that will allow it to be used as a field here, since theDatetype based off the built-inDatetype from thechronolibrary is not one.
- This is the
DateInputtype created for this mutation. Notice the function on line 57. It allows us to convertDateInputintoDate. And if you look back to the image on point 2 line 408, we map that conversion in order to send the date values into the query as aDatetype. The front-endDatePickergenerates a Date type, we convert it into aDateInputand use that down untildatabase_sql.rswhere we change it back into theDatetype.
- This part in
/graphql/src/query.rsconnects the back-end to the GraphQL front-end. We can give it a UserGroup guard as done here if needed. It calls the DataLoader fromdatabase_sql.rsand runs it.
- This part in
/graphql/src/queries.graphqlconnects directly to that function inqueries.rsshown in point 5. In line 327, it needs to take in the InputObject being used for the mutation. The name (in yellow can be anything). In line 328,updateDocumentMetadatais what it needs to be named. It is thecamelCaseversion of the function inqueries.rs. If you put something like,updateDocumentMetadata2, it won’t link to the function inquery.rsand won’t work.
- To use the mutation in the TypeScript front-end, we need to create a form context to send our user-inputted values into the GraphQL mutation (which connects further down to change the SQL database).
In line 19, declare document as the fragment in queries.graphql. This provides a structure for how we send data into the form. You can see it is based off the fields existing in the AnnotatedDoc type in index.ts. It is called again line 32 downwards
(values: { document },)See therunUpdateon line 44.documentis of typeDocumentMetadataUpdate InputObjectdefined indocument.rs. Forid, title, and writtenAt, we pass in the values collected from the fragment. Right hand side values need to be convertible into left hand side values. In the case ofwrittenAt, (if a value is inputted) we send it in as a typescript object{date, month year}. In point 4 theDateInputobject can be created in that way. So it can be passed in like that.
- The last step is the part that is actually visible by the user on the website. This
EditDocPanelcomponent has thedocumentprop, since that is where we extract the document id to be sent into the mutation. Line 68 callsuseForm()which is imported from the form context at the bottom of point 7's image.
In this case, the data is being sent into the from using 2 methods. The first method is using a `FormInput`, which is used for the `title` field. We use `FormInput` whenever we want the user to input a text field. Lines 111 to 122 handle the labelling and input field of the title value.
Lines 124 to 136 handle the labelling and picking (not input) of the date value. It is using an external library to select a date (no longer being used in current DAILP website deploy. We had to change it).
- This part of the
EditDocPanelcomponent handles the input of theidandwrittenAtvalues. Whenever a change is made to theDatePickerComponent, the state changes to reflect that. InuseEffect, we manually push theidanddatevalues to be used in the form. This is how to send predetermined values into the form. This function is found onunstable_FormState<V>in the node module/website/node_modules/reakit/ts/Form/FormState.d.tsfile
edit-doc-data-panel.tsx collects user input and sends it to form defined in edit-doc-data-form-context.tsx. With those values, it calls runUpdate which uses the GraphQL UpdateDocumentMetadata mutation.
Line 328 updateDocumentMetadata is the camelCase of update_document_metadata in queries.rs and links this GraphQL mutation to it. Then, it calls the DataLoader in database_sql.rs which calls the SQL file mutation which updates the database.
- CARE Principles
- Collective Decision-Making Process
- Data Resilience
- Culturally-Sensitive Information
- UX Design
- Metadata
- User Contributed Audio
- Audio Data Process
- Manuscript Annotation and Analysis
- Language Specific Limitations
- Annotation and Analysis (Before 2024)
- Code Standards
- AWS Diagnostics and Triage Guide
- Cloud Architecture
- Development Environments
- Data Representation
- Data Migration
- User Groups and Roles
- Wordpress Content
- Web Design & Accessibility