graphql финты ушами

когда надо в параметре передать [Int]! то так неззя надо делать объект который быдет иметь такое поле.

--------------------------------------------
Multiple fields
In a single GraphQL query, we can write as many root query fields as we need. In the server, all these fields will be processed in parallel and will give you the result as a whole.

{
  latestPost {
    title
  },

  authors {
    name
  }
}
src: https://medium.com/@tkssharma/wrapping-a-rest-api-in-graphql-querying-graphql-779345035949


make type-resolvers so you can go infinitely deep into the graph. I made a simple server example here that shows deep relationships. Because all the noun-fields are references, it goes infinitely deep for any query.
* можно добавлять параметризованные поля в типы, но по смыслу это то же самое что мульти запрос:
type Word{
    id: String!
    value: String!
    lang1(var1:Int):String!
}

data class Word(
        val id: Int,
        val value: String
) {
/* эта функция будет вызвана когда будет return из верзней функции запроса graphql query
 этот метод не имеет смысла вызывать напрямую, потому что
val dateFormat = env.getArgument("var1") as Int // dateFormat это null на уровне верхнего запроса
        element.lang1(dateFormat, env)
*/
    fun lang1(var1: Int, environment: DataFetchingEnvironment): String {
        println(var1)
        val dateFormat = environment.getArgument("var1")
        println(dateFormat)

        return "rand1"

    }

}
------------------------------------------
With that server, you can run a query like this, for example:

{
  hero {
    name
    friends {
      name
      friends {
        name
        friends {
          name
          friends: {
            name
          }
        }
      }
    }
  }
}
So, in your example, structure it like this:

query {
  user {
    id
    otherStuff {
      id
    }
  }
}
src: https://stackoverflow.com/a/49311322/2910338

--------------
GraphQL has a FetchDataEnvironment. You can use it by passing FetchDataEnvironment as the last variable in any resolver/query. Then, just call  environment.getContext().getHttpServletRequest.headers()

To anyone in the future - I'm sorry this code isn't exact, but your strong typing in your IDE will show you what I mean.
src: https://stackoverflow.com/questions/52197326/spring-boot-graphql-access-headers-from-arbitrary-resolver-code
-------------------------
https://graphql.org/learn/queries/#aliases
и это будет именем data....  empireHero: hero(episode: EMPIRE) {



Комментарии

Популярные сообщения из этого блога

kafka конспект однако

Дэвид Рок: Ваш мозг на работе - Разговоры в Гугле

Отслеживание Процесса загрузки с PHP и JavaScript