# GraphQL query for expression data

**URL:** https://community.opentargets.org/t/graphql-query-for-expression-data/1840
**Category:** Technical Support
**Created:** [26 June 2025 14:09 UTC](https://community.opentargets.org/t/graphql-query-for-expression-data/1840 "2025-06-26T14:09:53Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![mturchin20](https://avatars.discourse-cdn.com/v4/letter/m/b38774/32.png) [@mturchin20](https://community.opentargets.org/u/mturchin20)
#### Post date: [26 June 2025 14:09 UTC](https://community.opentargets.org/t/graphql-query-for-expression-data/1840/1 "2025-06-26T14:09:53Z")

</div>

Hello,

I am trying to run a GraphQL query to pull expression data for a target. Based on the schema ([https://api.platform.opentargets.org/api/v4/graphql/schema](https://api.platform.opentargets.org/api/v4/graphql/schema)), it looks like I should use the term ‘expressions’. However, the below query string appears to fail. If I remove ‘expressions’ from the term list in the string, it works. Am I using the right term to extract expression data? And related, is this just going to be the Expression Atlas data or will it include the GTEx data too?

Failing query:

```auto
query_string = "
  query target($ensemblId: String!){
    target(ensemblId: $ensemblId){
      id
      approvedSymbol
      biotype
      expressions
    }
  }
"

```

Successful query:

```auto
query_string = "
  query target($ensemblId: String!){
    target(ensemblId: $ensemblId){
      id
      approvedSymbol
      biotype
    }
  }
"

```

Thanks!  
Michael

---

<div class="post-metadata">

### Author: ![Ricardo\_Martinez](https://dub1.discourse-cdn.com/flex017/user_avatar/community.opentargets.org/ricardo_martinez/32/420_2.png) [@Ricardo\_Martinez](https://community.opentargets.org/u/Ricardo_Martinez)
#### Post date: [26 June 2025 14:22 UTC](https://community.opentargets.org/t/graphql-query-for-expression-data/1840/2 "2025-06-26T14:22:04Z")

</div>

Hello Michael,

When using the expressions field you’ll need to specify which fields you’re going to need as it is a structure. So you’ll need to specify if you need protein, tissue or rna or any combination and the same for each field.

The following is the specification for the Expression type and it’s subtypes.

```auto
 type Expression {
protein: ProteinExpression!
tissue: Tissue!
rna: RNAExpression!
}
type ProteinExpression {
reliability: Boolean!
level: Int!
cellType: [CellType!]!
}
type Tissue {
label: String!
organs: [String!]!
id: String!
anatomicalSystems: [String!]!
}
type RNAExpression {
zscore: Long!
unit: String!
level: Int!
value: Float!
}

```

---

<div class="post-metadata">

### Author: ![mturchin20](https://avatars.discourse-cdn.com/v4/letter/m/b38774/32.png) [@mturchin20](https://community.opentargets.org/u/mturchin20)
#### Post date: [26 June 2025 14:46 UTC](https://community.opentargets.org/t/graphql-query-for-expression-data/1840/3 "2025-06-26T14:46:41Z")

</div>

Hi Ricardo,

Great, thanks for these additional details. How would this query look then with these additional details? Should the below query work? I’m finding that it’s still failing.

```auto
query_string = "
  query target($ensemblId: String!){
    target(ensemblId: $ensemblId){
      id
      approvedSymbol
      biotype
      expressions {
        ProteinExpression {
          reliability
          level
        }
      }
    }
  }
"

```

---

<div class="post-metadata">

### Author: ![Ricardo\_Martinez](https://dub1.discourse-cdn.com/flex017/user_avatar/community.opentargets.org/ricardo_martinez/32/420_2.png) [@Ricardo\_Martinez](https://community.opentargets.org/u/Ricardo_Martinez)
#### Post date: [26 June 2025 14:52 UTC](https://community.opentargets.org/t/graphql-query-for-expression-data/1840/4 "2025-06-26T14:52:08Z")

</div>

> [@mturchin20](#):
>
> query target($ensemblId: String!){  
> target(ensemblId: $ensemblId){  
> id  
> approvedSymbol  
> biotype  
> expressions {  
> ProteinExpression {  
> reliability  
> level  
> }  
> }  
> }  
> }

this is because of an incorrect field name. You’re trying to query `ProteinExpression` which is the type but the field name is `protein`. The following is an example of the query including all the subtypes you could use it to select the ones you’re interested in

```auto
query target($ensemblId: String!) {
  target(ensemblId: $ensemblId) {
    id
    approvedSymbol
    biotype
    expressions {
      protein {
        reliability
        level
        cellType {
          reliability
          level
          name
        }
      }
      tissue {
        label
        organs
        id
        anatomicalSystems
      }
      rna {
        zscore
        unit
        level
        value
      }
    }
  }
}

```

---

<div class="post-metadata">

### Author: ![mturchin20](https://avatars.discourse-cdn.com/v4/letter/m/b38774/32.png) [@mturchin20](https://community.opentargets.org/u/mturchin20)
#### Post date: [26 June 2025 15:09 UTC](https://community.opentargets.org/t/graphql-query-for-expression-data/1840/5 "2025-06-26T15:09:36Z")

</div>

Ah got it, thanks Ricardo. I think I’m understanding more how the schema works now with the subtypes and how to properly access them.

---

<div class="post-metadata">

### Author: ![mturchin20](https://avatars.discourse-cdn.com/v4/letter/m/b38774/32.png) [@mturchin20](https://community.opentargets.org/u/mturchin20)
#### Post date: [26 June 2025 16:29 UTC](https://community.opentargets.org/t/graphql-query-for-expression-data/1840/6 "2025-06-26T16:29:56Z")

</div>

Hi again Ricardo – have another GraphQL/Schema question. I’m trying to pull L2G information for a credible set. But I’m having troubles following the scheme for L2G specifically. Below is the query I’m trying but it is failing. I think I’m not getting how to cut down on the output of the L2G query using the page specifications. Do you have any suggestions or clarifications? I’m basing this on the example API code you get when you look at a credible set in the platform.

```auto
query GwasCredibleSetsQuery($ensemblId: String!, $efoId: String!, $size: Int!) {
  target(ensemblId: $ensemblId) {
    approvedSymbol
  }
  disease(efoId: $efoId) {
    id
    name
    gwasCredibleSets: evidences(
      ensemblIds: [$ensemblId]
      enableIndirect: true
      datasourceIds: ["gwas_credible_sets"]
      size: $size
    ) {
      count
      rows {
        disease {
          id
          name
        }
        credibleSet {
          studyLocusId
          study {
            traitFromSource
            id
            projectId
            publicationFirstAuthor
            publicationDate
            pubmedId
            nSamples
          }
          variant {
            id
            chromosome
            position
            referenceAllele
            alternateAllele
          }
          pValueMantissa
          pValueExponent
          beta
          finemappingMethod
          confidence
          l2GPredictions (page {
            	index
            	size
          		}) {
            rows {
              score
            }
            count
          }
        }
        score
      }
    }
  }
}

```

If I remove the page{} part the query will run but I get the below error:

> “message”: “Query is too expensive. The response size is likely to be too large. Try requesting smaller page sizes or fewer items”

So I think I need to use the pagination part to cut down on the size of the output.

Thanks!

---

<div class="post-metadata">

### Author: ![mturchin20](https://avatars.discourse-cdn.com/v4/letter/m/b38774/32.png) [@mturchin20](https://community.opentargets.org/u/mturchin20)
#### Post date: [27 June 2025 13:28 UTC](https://community.opentargets.org/t/graphql-query-for-expression-data/1840/7 "2025-06-27T13:28:08Z")

</div>

Hi again,

Just adding here a partial solution for the page() syntex I found in case anyone else is looking to figure out the same thing. It works but also throws an error/warning at the end:

```auto
query GwasCredibleSetsQuery($ensemblId: String!, $efoId: String!, $size: Int!) {
  target(ensemblId: $ensemblId) {
    approvedSymbol
  }
  disease(efoId: $efoId) {
    id
    name
    gwasCredibleSets: evidences(
      ensemblIds: [$ensemblId]
      enableIndirect: true
      datasourceIds: ["gwas_credible_sets"]
      size: $size
    ) {
      count
      rows {
        disease {
          id
          name
        }
        credibleSet {
          studyLocusId
          study {
            traitFromSource
            id
            projectId
            publicationFirstAuthor
            publicationDate
            pubmedId
            nSamples
          }
          variant {
            id
            chromosome
            position
            referenceAllele
            alternateAllele
          }
          pValueMantissa
          pValueExponent
          beta
          finemappingMethod
          confidence
          l2GPredictions (page: [1,1]) {
            rows {
              score
            }
            count
          }
        }
        score
      }
    }
  }
}

```

---

<div class="post-metadata">

### Author: ![Ricardo\_Martinez](https://dub1.discourse-cdn.com/flex017/user_avatar/community.opentargets.org/ricardo_martinez/32/420_2.png) [@Ricardo\_Martinez](https://community.opentargets.org/u/Ricardo_Martinez)
#### Post date: [27 June 2025 15:16 UTC](https://community.opentargets.org/t/graphql-query-for-expression-data/1840/8 "2025-06-27T15:16:36Z")

</div>

Hello Michel,

No worries, the issue with the page argument is the format and values. When passing an argument to a query you’ll need to pass the name and value separated by colon `<name>: <value>`. In the query you sent you’re missing the colon between `page` and the bracket. Also, you’re missing the values for `index` and `size`. The following is an example with hard coded values for them but you can use parameters as well.

```auto
query GwasCredibleSetsQuery($ensemblId: String!, $efoId: String!, $size: Int!) {
  target(ensemblId: $ensemblId) {
    approvedSymbol
  }
  disease(efoId: $efoId) {
    id
    name
    gwasCredibleSets: evidences(
      ensemblIds: [$ensemblId]
      enableIndirect: true
      datasourceIds: ["gwas_credible_sets"]
      size: $size
    ) {
      count
      rows {
        disease {
          id
          name
        }
        credibleSet {
          studyLocusId
          study {
            traitFromSource
            id
            projectId
            publicationFirstAuthor
            publicationDate
            pubmedId
            nSamples
          }
          variant {
            id
            chromosome
            position
            referenceAllele
            alternateAllele
          }
          pValueMantissa
          pValueExponent
          beta
          finemappingMethod
          confidence
          l2GPredictions (page: {
            	index: 1
            	size: 1
          		}) {
            rows {
              score
            }
            count
          }
        }
        score
      }
    }
  }
}

```

---

<div class="post-metadata">

### Author: ![Ricardo\_Martinez](https://dub1.discourse-cdn.com/flex017/user_avatar/community.opentargets.org/ricardo_martinez/32/420_2.png) [@Ricardo\_Martinez](https://community.opentargets.org/u/Ricardo_Martinez)
#### Post date: [27 June 2025 15:26 UTC](https://community.opentargets.org/t/graphql-query-for-expression-data/1840/9 "2025-06-27T15:26:56Z")

</div>

The issue with this query is the way you’re passing the arguments. The following is an extract from the graphql js [documentation](https://www.graphql-js.org/docs/passing-arguments/). It’s a different language from the one we use (scala) but it explains the point on names and values. Also worth noting that the `page` argument is of type `Pagination` and because it’s a `type` and not a `scalar` you’ll need to use brackets (the same way as when asking for a field. An example of a `scalar` value would be `approvedSymbol` which is of type `String!` and an example of type would be `disease` which is of type `Disease`, the difference being that in the case of the query you don’t need to use the colon whilst in the arguments you do need them.

> When you call this API, you have to pass each argument by name. So for the server above, you could issue this GraphQL query to roll three six-sided dice:
> 
> ```auto
> {
> rollDice(numDice: 3, numSides: 6)
> }
> 
> ```

---

<div class="post-metadata">

### Author: ![mturchin20](https://avatars.discourse-cdn.com/v4/letter/m/b38774/32.png) [@mturchin20](https://community.opentargets.org/u/mturchin20)
#### Post date: [30 June 2025 02:55 UTC](https://community.opentargets.org/t/graphql-query-for-expression-data/1840/10 "2025-06-30T02:55:29Z")

</div>

This is great, thanks for all the additional details and clarifications Ricardo, much appreciated!
