Contentful logo

Contentful Community

Get Content Type of Media using GraphQL

Was wondering if it’s possible to get the Content-Type of an asset/media, via GraphQL. Am currently using cf-graphql, but can only seem to grab the asset’s Title, Description and URL.

Hi @apps,

I have double-checked with our engineer that is responsible for the GraphQL tool, and it would indeed not be possible to implement this at the short-term.

As you can check at the implentation of our GraphQL tool itself, assets our currently limited to the three properties that you mentioned (title, description,url), as:

const AssetType = new GraphQLObjectType({
  name: 'Asset',
  fields: {
    sys: {type: AssetSysType},
    title: {
      type: GraphQLString,
      resolve: asset =>  _get(asset, ['fields', 'title'])
    },
    description: {
      type: GraphQLString,
      resolve: asset => _get(asset, ['fields', 'description'])
    },
    url: {
      type: GraphQLString,
      resolve: asset => _get(asset, ['fields', 'file', 'url'])
    }
  }
});