Answers.Body: <p><code>RAND()</code> is the correct way to do this. (At least, it works in 3.5). One catch is that GraphQL queries are <a href="https://docs.craftcms.com/v3/config/config-settings.html#enablegraphqlcaching" rel="nofollow noreferrer">cached by default</a>, so your results will always be returned in the same random order until your cache is invalidated. If you're using Nuxt with a static target, your entries will be displayed in the same order until the cache is expired <em>and</em> your app is regenerated.</p>
  <p>Example of a working query:</p>
  <pre><code>{
    entries(section: &quot;posts&quot;, orderBy:&quot;RAND()&quot;) {
      title
      id
    }
  }
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-02-11T22:56:42.410Z
Answers.Text: Unfortunately, this stopped working after a recent update. Now I get "Illegal value for `orderBy` argument: `RAND()`".
Answers.UserDisplayName: David Jones
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-11-15T13:23:44.770Z
Answers.Text: It seems to work with `random()` now.
Answers.UserDisplayName: thomasjonas
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-08-02T00:03:48.193Z
Answers.LastActivityDate: 2020-08-02T00:03:48.193Z
Answers.UserDisplayName: Dalton Rooney
Body: <p>I'm currently building my first JAM stack app using Nuxt as my front-end framework and Craft as my headless CMS. I'm leveraging Apollo as my GraphQL interface client. I have it pulling data back just fine, but I want to shuffle the output to always be random. I know I could do this in a typical twig query with <code>.orderBy('RAND()')</code> but I need a way to shuffle that with my GraphQL endpoint. </p>
  
  <p>I know I can do this on the frontend by shuffling my <code>&lt;li&gt;</code>s or something, but would love for this to be more performant if I can help it.</p>
  
  <p>I've tried a few variations of the below but can't seem to get it to work. Is this possible?</p>
  
  <pre><code>apollo: {
    entries: {
      query: stories,
      prefetch: true,
      variables: {
         "section": ["stories"],
         "orderBy": "RAND()"
      }
    }
  },
  </code></pre>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-04-12T10:27:09.557Z
Comments.Text: This feels like it should work. Are you sure you are not hitting cached results?
Comments.UserDisplayName: Oli
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-04-12T19:44:21.623Z
Comments.Text: Hey Oli. Well I know RAND() is a PHP function. Maybe this isn't a Craft CMS question and more of an Apollo question?
Comments.UserDisplayName: Rob Erskine
Tags: <graphql><headless><vue>
Title: CraftCMS + GraphQL - orderBy Random?
ThreadText: # CraftCMS + GraphQL - orderBy Random?
  
  (Asked by: username_0 on 2020-04-12)
  
  I'm currently building my first JAM stack app using Nuxt as my front-end framework and Craft as my headless CMS. I'm leveraging Apollo as my GraphQL interface client. I have it pulling data back just fine, but I want to shuffle the output to always be random. I know I could do this in a typical twig query with `.orderBy('RAND()')` but I need a way to shuffle that with my GraphQL endpoint.
  
  I know I can do this on the frontend by shuffling my `<li>`s or something, but would love for this to be more performant if I can help it.
  
  I've tried a few variations of the below but can't seem to get it to work. Is this possible?
  
  ```
  apollo: {
    entries: {
      query: stories,
      prefetch: true,
      variables: {
         "section": ["stories"],
         "orderBy": "RAND()"
      }
    }
  },
  
  ```
  
  **Tags:** graphql, headless, vue
  
  > **Comments:**
  > **username_1**: This feels like it should work. Are you sure you are not hitting cached results?  
  > **username_0**: Hey Oli. Well I know RAND() is a PHP function. Maybe this isn't a Craft CMS question and more of an Apollo question?  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2020-08-02. Score: 2 | Accepted answer
  
  `RAND()` is the correct way to do this. (At least, it works in 3.5). One catch is that GraphQL queries are [cached by default](https://docs.craftcms.com/v3/config/config-settings.html#enablegraphqlcaching), so your results will always be returned in the same random order until your cache is invalidated. If you're using Nuxt with a static target, your entries will be displayed in the same order until the cache is expired *and* your app is regenerated.
  
  Example of a working query:
  
  ```
  {
    entries(section: "posts", orderBy:"RAND()") {
      title
      id
    }
  }
  
  ```
  
  > **Comments:**
  > **username_3**: Unfortunately, this stopped working after a recent update. Now I get "Illegal value for `orderBy` argument: `RAND()`".  
  > **username_4**: It seems to work with `random()` now.  
  
  ---
  
  