JabRef / jabref

Graphical Java application for managing BibTeX and biblatex (.bib) databases
https://devdocs.jabref.org
MIT License
3.63k stars 2.59k forks source link

Add integration with Jabref Online #7582

Open tobiasdiez opened 3 years ago

tobiasdiez commented 3 years ago

JabRefOnline now supports a (simple) API to create and login users as well as create and get documents (BibEntries). What is missing is the integration with JabRef. It would be nice if another developer could implement this so that I can concentrate fully on the server side. @koppor @calixtus @Siedlerchr interested?

To get started, follow the instructions in JabRefOnline to setup the local environment and run yarn dev to start the server. Afterwards the API can be reached at http://localhost:3000/api. Alternatively, you can also use the online version: https://jabref-online.herokuapp.com/user/register It is probably good to use a client-side Java library for Graphql, e.g. https://www.apollographql.com/docs/android/essentials/get-started-java/.

Here are few relevant queries:

Ali96kz commented 3 years ago

@tobiasdiez I wanna develop it. Am I need to develop UI under that task or it will be a separate task?

tobiasdiez commented 3 years ago

Nice, thanks for your interest!

I think one new dialog needs to be implemented, similar to to File > Shared database > Connect to a shared database, where people can enter their credentials. But you can also start by first implementing the backend, and write tests for it (also similar to the existing database integrations). Maybe @Siedlerchr already started working on it and/or wants to pair program with you.

Ali96kz commented 3 years ago

@tobiasdiez Do we really need apollographql-client ? we can simply send HTTP POST like these

{
  "operationName": "getDocumentById",
  "variables": {},
  "query": "query getDocumentById { getUserDocumentRaw(id: \"ckocxpcfg00281wvt8bcmdqsh\") {type citationKey fields {field value}}}",
}
tobiasdiez commented 3 years ago

Strictly speaking a client library is not needed, and you can go ahead as you said with simple http requests. However, a proper client gives you automatic error handling, parsing of the result, type security based on the schema and your graphql queries etc.

For example the code from https://www.apollographql.com/docs/android/essentials/get-started-java/

apolloClient.query(new LaunchDetailsQuery("83"))
        .enqueue(new ApolloCall.Callback<LaunchDetailsQuery.Data>() {
            @Override
            public void onResponse(@NotNull Response<LaunchDetailsQuery.Data> response) {
                Log.e("Apollo", "Launch site: " + response.getData().launch.site);
            }

            @Override
            public void onFailure(@NotNull ApolloException e) {
                Log.e("Apollo", "Error", e);
            }
        });

looks quite straigthforward and you don't need to handle all the underlying parsing/serialization. Note that LaunchDetailsQuery and LaunchDetailsQuery.Data are automatically generated classes.

Siedlerchr commented 3 years ago

I took a look at the apollo stuff and as usual it's the f*cking module system which throws errors again: I just added: implementation("com.apollographql.apollo:apollo-runtime:2.5.8")

module java.xml.bind reads package com.apollographql.apollo.cache.normalized from both apollo.normalized.cache.api.jvm and apollo.normalized.cache.jvm
error: module java.xml.bind reads package com.apollographql.apollo.cache.normalized.internal from both apollo.normalized.cache.api.jvm and apollo.normalized.cache.jvm
...
tobiasdiez commented 3 years ago

Did you report this already?

tobiasdiez commented 3 years ago

Also, we don't need the normalized cache (at least not now), so using the exclude mechanism should work. Something like

implementation ("com.apollographql.apollo:apollo-runtime:2.5.8") {
    exclude module: "apollo-normalized-cache"
    // or
    exclude group: 'com.apollographql.apollo', module: 'apollo-normalized-cache'
}
Siedlerchr commented 3 years ago

I had to exclue api as well:

  implementation ("com.apollographql.apollo:apollo-runtime:2.5.8") {
    exclude module: "apollo-normalized-cache"
    exclude module: "apollo-api"

   }

From the docs it seems like runtime should be sufficient. At least it compiles now.

Siedlerchr commented 3 years ago

I will look into the code gen stuff later

tobiasdiez commented 3 years ago

Nice, please also coordinate with @Ali96kz who already did good work towards the integration in https://github.com/JabRef/jabref/pull/7796.

Siedlerchr commented 3 years ago

I am having trouble with the mutation query, I never worked with graphql before, but in the playground it seems to work:

https://www.graphql-code-generator.com/

grafik

I also tried to run it locally using the java codegen plugin on the schema:

schema: https://jabref-online.herokuapp.com/api
documents: ./query/*.graphql
generates:
  ./app/src/main/java/:
    preset: java-apollo-android
    config:
      package: "org.jabref.model.generated.graphql"
      typePackage: "org.jabref.model.generated.Types"
      fragmentPackage: "org.jabref.model.generated.Fragment"
    plugins:
      - java-apollo-android

local stack trace


 Found 1 error

  ✖ ./app/src/main/java/
    TypeError: Cannot read property 'value' of undefined
        at /Users/christophs/workspace/JabRefOnline/node_modules/@graphql-codegen/java-apollo-android/index.cjs.js:1319:43
        at Array.map (<anonymous>)
        at Object.buildGeneratesSection (/Users/christophs/workspace/JabRefOnline/node_modules/@graphql-codegen/java-apollo
-android/index.cjs.js:1318:30)
        at /Users/christophs/workspace/JabRefOnline/node_modules/@graphql-codegen/cli/bin.js:948:64
        at async Task.task (/Users/christophs/workspace/JabRefOnline/node_modules/@graphql-codegen/cli/bin.js:760:17)
    TypeError: Cannot read property 'value' of undefined
        at /Users/christophs/workspace/JabRefOnline/node_modules/@graphql-codegen/java-apollo-android/index.cjs.js:1319:43
        at Array.map (<anonymous>)
        at Object.buildGeneratesSection (/Users/christophs/workspace/JabRefOnline/node_modules/@graphql-codegen/java-apollo
-android/index.cjs.js:1318:30)
        at /Users/christophs/workspace/JabRefOnline/node_modules/@graphql-codegen/cli/bin.js:948:64
        at async Task.task (/Users/christophs/workspace/JabRefOnline/node_modules/@graphql-codegen/cli/bin.js:760:17)
Siedlerchr commented 3 years ago

Ah fuck this shit, would have been to easy with the api exclusion. and the generated code is also somehow useless

tobiasdiez commented 3 years ago

Why did you needed to exclude the api package? If it was for an subdependency, you can try to add a separate implementation(....api) with its own exclude.

Siedlerchr commented 3 years ago

another split dependency...

tobiasdiez commented 3 years ago

OK, then using a finer exclude pattern should work indeed.

implementation ("com.apollographql.apollo:apollo-runtime:2.5.8") {
    exclude module: "apollo-normalized-cache"
}
 implementation ("com.apollographql.apollo:apollo-api:2.5.8") {
    exclude module: "apollo-split-package"
}
Ali96kz commented 3 years ago

@tobiasdiez @Siedlerchr I will complete these issue, I just need help with adding dependency on apollographql

Siedlerchr commented 3 years ago

@tobiasdiez The problem is already in the runtime dependency.

error: module java.xml.bind reads package com.apollographql.apollo from both apollo.api.jvm and apollo.runtime error: module java.xml.bind reads package com.apollographql.apollo.exception from both apollo.api.jvm and apollo.runtime

Gradle shows the following dependency graph (./gradlew dependencies) So I guess it should be sufficient to only inlcude the api. However, this contradicts a bit what is written here https://github.com/apollographql/apollo-android#releases


- com.apollographql.apollo:apollo-runtime:2.5.8
|    +--- com.apollographql.apollo:apollo-api:2.5.8
|    |    \--- com.apollographql.apollo:apollo-api-jvm:2.5.8
|    |         +--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.5.0
|    |         |    +--- org.jetbrains.kotlin:kotlin-stdlib:1.5.0
|    |         |    |    +--- org.jetbrains:annotations:13.0 -> 15.0
|    |         |    |    \--- org.jetbrains.kotlin:kotlin-stdlib-common:1.5.0
|    |         |    \--- org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.5.0
|    |         |         \--- org.jetbrains.kotlin:kotlin-stdlib:1.5.0 (*)
|    |         +--- com.squareup.okio:okio-multiplatform:2.9.0
|    |         |    \--- com.squareup.okio:okio:2.9.0
|    |         |         +--- org.jetbrains.kotlin:kotlin-stdlib:1.4.10 -> 1.5.0 (*)
|    |         |         \--- org.jetbrains.kotlin:kotlin-stdlib-common:1.4.10 -> 1.5.0
|    |         \--- org.jetbrains.kotlin:kotlin-stdlib-common:1.5.0
|    +--- com.apollographql.apollo:apollo-http-cache-api:2.5.8
|    |    +--- com.squareup.okio:okio-multiplatform:2.9.0 (*)
|    |    \--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.5.0 (*)
tobiasdiez commented 3 years ago

@Siedlerchr https://github.com/JabRef/jabref/pull/7796#issuecomment-855279605

I don't have a dev pc available right now so I cannot add the jar file manually. But I think this should work.

The apollo-runtime is really necessary, see https://github.com/apollographql/apollo-android/tree/main/apollo-runtime/src/main/java/com/apollographql/apollo