PHP code example of getpop / field-query

1. Go to this page and download the library: Download getpop/field-query library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

getpop / field-query example snippets

 bash
composer 

use PoP\FieldQuery\Facades\Query\FieldQueryInterpreterFacade;

$fieldQueryInterpreter = FieldQueryInterpreterFacade::getInstance();

// To create a field from its elements
$field = /* @todo Re-do this code! Left undone */ new Field($fieldName, $fieldArgs, $fieldAlias, $skipOutputIfNull, $fieldDirectives);

// To retrieve the elements from a field
$fieldName = $fieldQueryInterpreter->getFieldName($field);
$fieldArgs = $fieldQueryInterpreter->getFieldArgs($field);

// All other functions listed in FieldQueryInterpreterInterface
// ...

fieldName(fieldArgs)[@alias]?<fieldDirective(directiveArgs)>

fieldName(
  fieldArgs
)[@alias]?<
  fieldDirective(
    directiveArgs
  )
>

fieldName1@alias1,
fieldName2(
  fieldArgs2
)[@alias2]?<
  fieldDirective2
>

/?query=
  id|
  fullSchema

/?query=
  posts.
    author.
      id

/?query=
  posts.
    author.
      id|
      name|
      url

/?query=
  posts.
    id|
    title|
    author.
      id|
      name|
      url

/?query=
  posts.
    author.
      id|
      name|
      url,
  posts.
    comments.
      id|
      content

/?query=
  posts.
    author.
      id|
      name|
      url;
      
  posts.
    comments.
      id|
      content

/?query=
  posts.
    author.
      id|
      name|
      url,
  self.
    self.
      posts.
        comments.
        id|
        content

/?query=
  posts(filter: { search: template }).
    id|
    title|
    date

/?query=
  posts.
    id|
    title|
    dateStr(format:d/m/Y)

/?query=
  posts.
    id|
    title|
    dateStr(d/m/Y)

/?query=
  posts.
    id|
    title|
    dateStr(d/m/Y)@formattedDate

/?query=posts.
  id|
  title|
  dateStr|
  dateStr(d/m/Y)

/?query=
  users.
    posts.
      author.
        id|
        name,
  users.
    posts.
      comments.
        id|
        content

/?query=
  users.
    posts[userposts].
      author.
        id|
        name,
    [userposts].
      comments.
        id|
        content

/?query=
  users.
    posts[@userposts].
      author.
        id|
        name,
    [userposts].
      comments.id|
      content

1. /?
  format=d/m/Y&
  query=
    posts.
      id|
      title|
      dateStr($format)

2. /?
  variables[format]=d/m/Y&
  query=
    posts.
      id|
      title|
      dateStr($format)

1. /?
userData=
  id|
  name|
  url&
query=
  users.
    --userData|
    posts.
      comments.
        author.
          --userData

2. /?
fragments[userData]=
  id|
  name|
  url&
query=
  users.
    --userData|
    posts.
      comments.
        author.
          --userData

1. /?
=
  posts.
    id|
    title|
    featuredImage<
      sts.
    id|
    title|
    featuredImage<
      (if:$skip)
    >.
      id|
      src

4. /?
skip=false&
query=
  posts.
    id|
    title|
    featuredImage<
      skip(if:$skip)
    >.
      id|
      src

1. /?query=not(true)

2. /?query=or([1, 0])

3. /?query=and([1, 0])

4. /?query=if(true, Show this text, Hide this text)

5. /?query=equals(first text, second text)

6. /?query=isNull(),isNull(something)

7. /?query=sprintf(
  %s is %s, [
    PoP API, 
    cool
  ])

8. /?query=echo([
  name: PoP API,
  status: cool
])

9. /?query=arrayValues([
  name: PoP API,
  status: cool
])

1. /?query=context

2. /?query=
  var(route)|
  var(target)@target|
  var(datastructure)

1. /?query=
  posts.
    hasComments|
    not(hasComments())

2. /?query=
  posts.
    hasComments|
    hasFeaturedImage|
    or([
      hasComments(),
      hasFeaturedImage()
    ])

3. /?query=
  var(fetching-site)|
  posts.
    hasFeaturedImage|
    and([
      hasFeaturedImage(),
      var(fetching-site)
    ])

4. /?query=
  posts.
  if (
    hasComments(),
    sprintf(
      Post with title '%s' has %s comments, [
      title(), 
      commentCount()
    ]),
    sprintf(
      Post with ID %s was created on %s, [
      id(),
      dateStr(d/m/Y)
    ])
  )@postDesc

5. /?query=users.
  name|
  equals(
    name(), 
    leo
  )

6. /?query=
  posts.
    featuredImage|
    isNull(featuredImage())

/?query=
  posts.
    sprintf(
      "This post has %s comment(s)", [
      commentCount()
    ])@postDesc

1. /?query=
  posts.
    id|
    title|
    featuredImage<
      le|
    featuredImage<
      skip(if:isNull(featuredImage()))
    >.
      id|
      src

/?query=
  posts.
    id|
    title|
    featuredImage.
      id|
      src

/?query=
  posts.
    id|
    title|
    featuredImage?.
      id|
      src

/?query=
  echo([
    [banana, apple],
    [strawberry, grape, melon]
  ])@fruitJoin<
    forEach<
      applyFunction(
        function: arrayJoin,
        addArguments: [
          array: %{value}%,
          separator: "---"
        ]
      )
    >
  >

/?query=
  echo([
    {
      text: Hello my friends,
      translateTo: fr
    },
    {
      text: How do you like this software so far?,
      translateTo: es
    }
  ])@translated<
    forEach<
      advancePointerInArrayOrObject(
        path: text,
        appendExpressions: {
          toLang:extract(%{value}%,translateTo)
        }
      )<
        translateMultiple(
          from: en,
          to: %{toLang}%,
          oneLanguagePerField: true
        )
      >
    >
  >

/?
postData=
  id|
  title|
  --nestedPostData|
  dateStr(format:$format)&
nestedPostData=
  comments<
    : {
      limit:$limit
    },
    sort: {
      order:$order
    }
  ).
    --postData|
    author.
      posts(
        pagination: {
          limit:$limit
        }
      ).
        --postData

/?
fragments[props]=
  title|
  date& 
query=
  posts.
    id|
    --props<
      

/?
fragments[props]=
  title|
  url<
    <
      

/?
fragments[props]=
  title|
  url|
  featuredImage&
query=
  posts.
    id|
    --props@prop

/?query=posts.id|--props@original|--props@translated<translate(from:en,to:es)>&fragments[props]=title|content

/?
fragments[props]=
  title|
  url|
  featuredImage&
query=
  posts.
    id|
    --props?

/?
fragments[props]=
  title|
  url<
      id|
    hasComments|
    --props?<
      
 bash
$ composer test
 php
\PoP\Root\App::stockAndInitializeModuleClasses([([
    \PoP\FieldQuery\Module::class,
]);