-1

I want to make parameterized requests from the Apollo client to the Apollo server.

On client:

const GET_VALUES = gql`
query Values($desc: String!) {      
    Values      
}    
`;
function ValueSelector({ pickValue, dirDesc }) { 
const { loading, data, error } = useQuery(GET_VALUES, {
variables: { dirDesc },
 });
}

On server (schema):

type Query {
Values(desc: String!): [String]
@cypher(
  statement: "MATCH (:Dir{description:$desc})-[:value]->(v) RETURN collect(v.TXTLG)"
 )  
}

Result:

[GraphQL error]: Message: Field "Values" argument "desc" of type "String!" is required, but it was not provided., Location: [object Object], Path: undefined
[Network error]: ServerError: Response not successful: Received status code 400
4
  • dirDesc provided instead of desc
    – xadm
    May 22, 2020 at 9:30
  • @xadm I changed aliases but the result is the same
    – a1olegs
    May 22, 2020 at 10:00
  • GraphQLError: Syntax Error: Expected Name, found }
    – a1olegs
    May 22, 2020 at 10:26
  • graphql.org/learn/queries/#variables
    – xadm
    May 22, 2020 at 10:41

3 Answers 3

1

You should use desc instead of dirDesc in variables param of useQuery. Try this:

const { loading, data, error } = useQuery(GET_VALUES, {
variables: { desc: dirDesc },
 });

2
  • result is the same (
    – a1olegs
    May 22, 2020 at 10:15
  • You should change you query to this const GET_VALUES = gql` query Values($desc: String!) { Values(desc: $desc) } @a1olegs
    – Michael
    May 22, 2020 at 12:32
0
const GET_VALUES = gql`
    query Values($desc: String!) {      
      Values(desc: $desc)  
    }    
  `;

function ValueSelector({ pickValue, dirDesc }) {   
  const { loading, data, error } = useQuery(GET_VALUES, {
    variables: { desc:dirDesc},
   });
0

Your query declaration on the client is missing the actual variable. It should be something like this

const GET_VALUES = gql`
    query Values($desc: String!) {      
         Values(dirDesc: $desc)      
    }    
`;

Then you can use useQuery passing dirDesc.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.