1

I am using streamlit to build a frontend for doing crud operations. The backend API is a neo4j graphql API and I am trying to do mutations from the form data in streamlit. I am receiving this error below.I was unable to rectify this error need help

raise GraphQLSyntaxError(graphql.error.syntax_error.GraphQLSyntaxError: Syntax Error: Expected Name, found '{'.

code below

import os
from gql import gql, Client
from gql.transport.aiohttp import AIOHTTPTransport

transport = AIOHTTPTransport(url="https://graphql-newone.herokuapp.com/")
client = Client(transport=transport, fetch_schema_from_transport=True)

st.title("Sanjeevan")

st.sidebar.markdown("# Main page ")
def create_user(name, age, sex, weight, nationality, birth_type,drinking):
  query = gql(
        """
        mutation {
                createUsers(input:{
                user_name: "${name}"
                age: ${age}
                sex: ${sex}
                weight: ${weight}
                nationality:${nationality}
                birth_type: ${birth_type}
                drinking: ${drinking}
                  })
                  {
                    users{
                      user_name
                    }
                  }
              }
        """
  )

  params = {"user_name":name, "age":age, "sex":sex, "weight":weight, "nationality":nationality,"birth_type":birth_type,"drinking":drinking}
  result = client.execute(query, variable_values=params)
  todo = result['createUsers']
  st.session_state.todos.append(todo)
  return result 


with st.form(key="user_form", clear_on_submit=True):
    name = st.text_input(label="Enter Name")
    age = st.number_input(label="Enter Age")
    sex = st.selectbox('Sex',('Male','Female'))
    weight = st.number_input(label="Enter Weight")
    nationality = st.selectbox('Nationality',('Indian','Non-Indian'))
    birth_type = st.selectbox('Birth Type',('Normal','Cesarean'))
    # smoking = st.selectbox('Smoking',('true','false'))
    drinking = st.selectbox('Drinking',('true','false'))
    # history_of_ibd = st.selectbox('History',('true','false'))
    submitted = st.form_submit_button("Submit")

    if submitted:
      create_user(name,age,sex, weight,nationality,birth_type,drinking)

0 Answers0