I'm implementing GraphQL to query data from the web with web driver.

My problem is that I cannot figure out how to use one argument as input for 2 different queries. So basically It is querying data from 2 different sites and has the same input which is usually 4 character Symbol.

What I want my query to look like.

{
   Webpage1(symbol:"AABC"){
       data_from_site,
       some_other_data
       Webpage2(symbol:"AABC"){ ##get rid of this Double attribute entry
          data_from_page2
       }  
   }
}

How can I pass only one argument be And get data from both sites? So it will be in the root context for the resolver to use.

I'm fairly new to GraphQL and have tried defining separate GraphQLObjectType in order to solve this problem. But what I'm really looking for is unified data in the same object and arguments parsed from the parent object.

var schema = new GraphQLSchema({
    query: new GraphQLObjectType({
        name: 'Query',
        fields: {
            Webpage1: {
                type: Website1,
                args: {
                    symbol: { type: GraphQLString },
                    //date: { type: GraphQLString }

                },
                resolve: function (_, { symbol }) {
                    return {
                        symbol
                    };
                }
            },
            Webpage2: {
                type: History,
                resolve: function (_, { symbol }) {
                    return {
                        symbol
                    };
                }
            }
        }
    })
})

1 Answers

3
Daniel Rearden On

If I'm understanding your question correctly, you can keep your schema as is and just utilize a variable when sending your query:

query MyQuery($mySymbol: String){
  Webpage1(symbol:$mySymbol) {
    data_from_site
    some_other_data
  }
  Webpage2(symbol:$mySymbol) {
    data_from_page2  
  }
}

Variables are defined at the top of your document, as part of your operation definition. Once defined, they can used any number of times inside the document anywhere you would use the same kind of literal value. You can check out the official tutorial on variables here and the spec here.